这些操作在网上都可以百度得到,为了便于记忆自己再根据理解总结在一起。---------励志做一个优雅的网上搬运工
1.建立dataframe
(1)Dict to Dataframe
df = pd.DataFrame({‘key1‘:[‘a‘,‘a‘,‘b‘,‘b‘,‘a‘],‘key2‘:[‘one‘,‘two‘,‘one‘,‘two‘,‘one‘],‘data1‘:np.random.randn(5),‘data2‘:np.random.randn(5)}) df data1 data2 key1 key2 0 -0.484486 -1.404184 a one 1 -1.541437 0.549591 a two 2 -0.015287 -1.589111 b one 3 -0.069614 -0.513824 b two 4 -0.704788 0.395147 a one
(2)Series to Dataframe
df2=pd.DataFrame(np.arange(16).reshape((4,4)),index=[‘one‘,‘two‘,‘three‘,‘four‘],columns=[‘a‘,‘b‘,‘c‘,‘d‘]) df2 a b c d one 0 1 2 3 two 4 5 6 7 three 8 9 10 11 four 12 13 14 15
(3)pd.read_csv()
2.groupby