其他
Pandas 可视化综合指南:手把手从零教你绘制数据图表
(给Python开发者加星标,提升Python技能)
转自:量子位(ID:QbitAI),编译:晓查
1import pandas as pd
2df=pd.read_csv(‘./world-happiness-report-2019.csv’)
3df.head(3)
1df.rename(columns={“Country (region)”: “Country”, “Log of GDPper capita”: “Log_GDP_per_capita”, “Healthy life
2expectancy”:”Health_life_expect”},inplace=True)
3df.columns
1%matplotlib tk
2df1=df[:5]
3df1.plot(‘Country’,[‘Corruption’,’Freedom’,’Generosity’,’Social support’],kind = ‘bar’)
1%matplotlib tk
2df1=df[:5]
3df1.plot(‘Country’,[7,6,8,5],kind = ‘bar’)
1df1=df[:5]
2df1.plot(‘Country’,[‘Corruption’,’Freedom’,’Generosity’,’Social support’],kind = ‘line’)
1df[:5].plot(x=’Country’,kind=’box’)
1df.plot(x=’Corruption’,y=’Freedom’,kind=’scatter’,color=’R’)
1from pandas.plotting import table
2df1=df[:5]
3df1=df.loc[:5,[‘Country (region)’,’Corruption’,’Freedom’,’Generosity’,’Social support’]]
4ax=df1.plot(‘Country (region)’,[‘Corruption’,’Freedom’,’Generosity’,’Social support’], kind = ‘bar’, title =’Bar Plot’,legend=None)
5table(ax, np.round(df1.describe(), 2),loc=’upper right’)
取值范围
1df1=df[:20]
2df1[‘Freedom’].plot(kind=’line’,xlim=(0,20),ylim=(0,100))
x、y轴刻度
1df[:20][‘Freedom’].plot(kind=’line’,xlim=(0,20),ylim=(0,100),color=’red’,xticks=([0,10,15,20]),yticks=([0,50,70,100]), title = ‘xticks’)
1df[:20][‘Freedom’].plot(kind=’line’,xlim=(0,20),ylim=(0,100),color=’red’,xticks=([w1 for w in range(20)]),yticks=([w10 for w in range(40)]))
1ax=df[:20][‘Freedom’].plot(kind=’line’,xlim=(0,20),ylim=(0,100),color=’red’,xticks=([0,10,20]),yticks=([w*30 for w in range(40)]))
2ax.set_xticklabels([‘Low’,’Med’,’High’])
对数坐标
1df[:20][‘Freedom’].plot(kind=’line’,xlim=(0,1000),ylim=(0,100),color=’red’,logx=True)
https://kanoki.org/2019/09/16/dataframe-visualization-with-pandas-plot/
https://www.kaggle.com/PromptCloudHQ/world-happiness-report-2019/version/1
推荐阅读
(点击标题可跳转阅读)
用 Scikit-Learn 和 Pandas 学习线性回归觉得本文对你有帮助?请分享给更多人
关注「Python开发者」加星标,提升Python技能
好文章,我在看❤️