groupby()分类:
返回series写法:
drinks.groupby('continent').beer_servings.agg('mean')
drinks.groupby('continent').beer_servings.mean()
返回dataframe写法:
drinks[['beer_servings','continent']].groupby('continent').agg({'beer_servings':'mean'})
drinks.groupby('continent')['beer_servings','continent'].mean()
设置datetime64[ns]:
data["Yr_Mo_Dy"] = pd.to_datetime(data["Yr_Mo_Dy"])
提取数据:
euro12[euro12.Goals > 6]
euro12[euro12.Team.str.startswith(‘G’)]
euro12.iloc[: , 0:7]
euro12.loc[euro12.Team.isin([‘England’, ‘Italy’, ‘Russia’]), [‘Team’,‘Shooting Accuracy’]]
euro12.loc[‘Team’:‘Shooting Accuracy’,:]
dataframe迭代:
iteritems()迭代为series(k,v),如:
df = pd.DataFrame(np.random.randn(5,4),columns=['A','B','C','D'])
for k,v in df.iteritems():
print(k,v)
iterrows()迭代,返回索引值以及包含每行数据的序列,如:
df = pd.DataFrame(np.random.randn(5,4),columns=['A','B','C','D'])
for index,row in df.iterrows():
print(index,row)
itertuples()迭代,返回元组,第一个值是相应的索引,后面的值是行值,如:
df = pd.DataFrame(np.random.randn(5,4),columns=['A','B','C','D'])
for row in df.itertuples():
print(row)