import pandas as pd import numpy as np a = pd.date_range('20130101', periods=6) b = pd.DataFrame(np.arange(24).reshape((6,4)),index=a, columns=['A','B','C','D']) #简单选择 print(b['A']) print(b.A) """ 2013-01-01 0 2013-01-02 4 2013-01-03 8 2013-01-04 12 2013-01-05 16 2013-01-06 20 Freq: D, Name: A, dtype: int64 """ #多行跨越选择 print(b[0:3]) #选择前三行 print(b['20130102':'20130104']) #选择20130102,20130103,20130104 #IOC选择器 print(b.loc['20130102']) #选择'20130102'这一行 print(b.loc[:,['A','B']]) #选择'A','B'这两列 print(b.loc['20130102',['A','B']]) #选择'20130102'这一行的'A','B'这两列 #iIOC选择器 print(b.iloc[3,1]) #选择第四行第二列的元素 # 13 print(b.iloc[3:5,1:3]) #选择第四、五行第二、三列 """ B C 2013-01-04 13 14 2013-01-05 17 18 """ print(b.iloc[[1,3,5],1:3]) """ B C 2013-01-02 5 6 2013-01-04 13 14 2013-01-06 21 22 """ #ix选择器 print(b.ix[:3,['A','C']]) #选择'A'和'C'的两列前三行的数据。 #通过判断条件筛选 print(b[b.A>8])
数据分析Pandas(2)-数据选择
最新推荐文章于 2023-04-15 22:47:11 发布