我有一个包含多个变量的数据框架,并希望在图的网格上绘制多变量关系。以下是数据帧:
df=pd.DataFrame({'Year':2005,2005,2005,2005,2006,2006,2006,2006,2007,2007,2007,2007,2008,2008,2008,2008,‘月’:‘六月’,‘六月’,‘七月’,‘七月’,‘大门’:'A','B','A','B','A','B','A','B','A','B',,‘乘客’:20000,30000, 25000,30000,20000,25000,25000,30000,30000,35000,20000,15000,20000,25000,15000,15000})
我想绘制每个月和每个登机口的旅客(y轴)随年份(x轴)的变化(直方图)。例如,其中一个子图将显示A登机口6月份的乘客与年份。
发布于 2019-08-27 09:56:49
你有一点错误的数据。你可以重写它。
2005年:
六月->A->20000
7月->B->30000
六月->A->25000
7月->B->30000
如您所见,第1行和第3行在同一个月有不同的数字。我给自己修好了。
import pandas as pd
df=pd.DataFrame({'Year':[2005,2005,2005,2005,2006,2006,2006,2006,2007,2007,2007,2007,2008,2008,2008,2008],
'Month': ['June', 'July','June', 'July','June', 'July','June', 'July','June', 'July','June', 'July','June', 'July','June', 'July',],
'Gate': ['A','B', 'B','A','A','B', 'B','A','A','B', 'B','A','A','B', 'B','A',],
'Passengers':[20000, 30000,25000,30000,20000, 25000, 25000,30000,30000,35000,20000,15000,20000,25000,15000,15000]})
df.pivot_table('Passengers',['Year','Gate','Month'])
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
df.pivot_table('Passengers',index='Year',columns=['Gate','Month']).plot()
plt.ylabel('number of passengers')我想这就足够了。
https://stackoverflow.com/questions/57666492
复制相似问题