平均列值的散点图
Scatter plots from averaging a columns values
我正在使用 csv 文件中的 2 列:Month_num 和 Freight_In_(吨)
我正在尝试绘制从 1987 年到 2016 年每个月的运费平均值。我目前可以以 table 格式显示每个月的平均运费,但我正在努力将其显示为在散点图中显示。
这是我当前的代码。
from matplotlib import pyplot as plt
import pandas as pd
df = pd.read_csv('CityPairs.csv')
Month = df.groupby(['Month_num'])['Freight_In_(tonnes)']
Month.mean()
plt.scatter(df['Month_num'], df['Freight_In_(tonnes)'])
plt.show()
试试这个:
df.groupby(['Month_num']).mean().reset_index().plot(kind='scatter',x='Month_num',y='Freight_In_(tonnes)')
我正在使用 csv 文件中的 2 列:Month_num 和 Freight_In_(吨)
我正在尝试绘制从 1987 年到 2016 年每个月的运费平均值。我目前可以以 table 格式显示每个月的平均运费,但我正在努力将其显示为在散点图中显示。
这是我当前的代码。
from matplotlib import pyplot as plt
import pandas as pd
df = pd.read_csv('CityPairs.csv')
Month = df.groupby(['Month_num'])['Freight_In_(tonnes)']
Month.mean()
plt.scatter(df['Month_num'], df['Freight_In_(tonnes)'])
plt.show()
试试这个:
df.groupby(['Month_num']).mean().reset_index().plot(kind='scatter',x='Month_num',y='Freight_In_(tonnes)')