pandas 使用技巧總結(jié)
1. 獲取列的元素集合
? ? df.column_name.unique()
2. 從dict產(chǎn)生dataframe:
? ? some_dict={key:value}
? ? some_df=pd.DataFrame.from_dict(some_dict)
3. 列重命名
? ? df.rename(columns={'old':'new'})
4. 柱狀圖加數(shù)值
? ? ax=bucketed_data.plot.bar()
? ? for p in ax.patches:
????ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))
5. 子圖調(diào)整間距
? ??fig,ax=plt.subplots(nrows=3,ncols=1,figsize=(9,9))
? ??fig.tight_layout()