In [17]: stat = DataFrame.from_dict({"Beijing":{"People":3100,"Area":540,"GDP":3000},"Guangzhou":{"People":np.nan,"Area":370,"GDP":2500},"Shanghai": ...: {"People":2800,"Area":500,"GDP":3100},"Shenzhen":{"People":1800,"Area":np.nan,"GDP":2100}},orient='index')
In [18]: stat Out[18]: People Area GDP Beijing 3100.0 540.0 3000 Guangzhou NaN 370.0 2500 Shanghai 2800.0 500.0 3100 Shenzhen 1800.0 NaN 2100
In [20]: stat.isnull() Out[20]: People Area GDP Beijing False False False Guangzhou True False False Shanghai False False False Shenzhen False True False
In [24]: stat = stat.dropna()
In [25]: stat Out[25]: People Area GDP Beijing 3100.0 540.0 3000 Shanghai 2800.0 500.0 3100
In [40]: people['title'] = people['Gender'].map(NormalizeName) In [43]: people Out[43]: Gender Age Occupation title Lao Shi Female 55 公司职员 Mrs Xiao Wei Male 23 公司职员 Mr Xiao Zhang Male 24 教师 Mr xiao Wang Female 25 教师 Mrs
index : a column, Grouper, array which has the same length as data, or list of them. Keys to group by on the pivot table index. If an array is passed, it is being used as the same manner as column values.
columns : a column, Grouper, array which has the same length as data, or list of them. Keys to group by on the pivot table column. If an array is passed, it is being used as the same manner as column values.
aggfunc : function to use for aggregation, defaulting to numpy.mean.
导入和导出数据
从CSV导入数据
1 2 3 4 5 6 7 8
In [72]: jg = pd.read_csv('jg-2017-12-utf8.csv',parse_dates=True,index_col=0)
In [82]: del jg['结算汇率'] In [84]: jg.to_csv('test.csv') In [90]: cat test.csv 成交日期,摘要,证券名称,合同编号,成交数量,成交均价,成交金额,手续费,印花税,其他杂费,发生金额,股东帐户,备注,操作,证券代码 2017-12-01,基金资金拨出,天天发1,0,0,1.0,0,0.0,0.0,0.0,-36118.59,99F6983257,122.0,其他,940018