close
import pandas as pd import numpy as np
dates=pd.date_range('20160101',periods=6)創造日期1號到6號被放在下一行程式碼的索引值 df=pd.DataFrame(np.random.randn(6,4),index=dates,columns=['a','b','c','d']) a b c d 2016-01-01 0.094392 0.865838 -1.044691 1.037849 2016-01-02 0.475582 0.936830 -0.557602 -0.278023 2016-01-03 0.488146 -1.356294 -0.814207 0.370579 2016-01-04 -0.999719 -1.608016 -2.232661 0.396275 2016-01-05 -0.343536 0.134904 0.537597 -1.712434 2016-01-06 -0.232216 -0.420282 -0.408076 -0.001722 df['e']=0增加數據e整行皆為0 df['f']=pd.Series([1,2,3,4,5,6],index=pd.date_range('20160101',periods=6))
--------------------------------------------------------------------------------- df1=pd.DataFrame(np.arange(12).reshape((3,4)))索引值與標籤預設從0開始 0 1 2 3 0 0 1 2 3 1 4 5 6 7 2 8 9 10 11 ---------------------------------------------------------------------------------------index and columns df2=pd.DataFrame({'A':1., 'B':pd.Timestamp('20130102'), 'C':pd.Series(1,index=list(range(4)),dtype='float32'), 'D':np.array([3]*4,dtype='int32'), 'E':pd.Categorical(["test","train","test","train"]), 'F':'foo'},index=pd.Series([1,5,64,22])) A B C D E F 1 1.0 2013-01-02 1.0 3 test foo 5 1.0 2013-01-02 NaN 3 train foo 64 1.0 2013-01-02 NaN 3 test foo 22 1.0 2013-01-02 NaN 3 train foo
全站熱搜