如何绘制数据框中的值?

问题描述 投票:0回答:1

我有一个数据框,

test
,其中包含自 1951 年以来某个城市的冬季气温。我想绘制名为
wintermean
的列中包含的温度,但是当我尝试使用
plt.plot(test.wintermean.values)
执行此操作时,出现以下错误:TypeError:无法将系列转换为 。以下是
test
wintermean
test.wintermean.values
的外观: 如何绘制此温度数据?

python pandas dataframe numpy weather
1个回答
0
投票

我认为你需要清理数据。可能有一些非数值。例如“-”或“?”。首先转换那些

 test['wintermean'] = pd.to_numeric(test['wintermean'], errors='coerce')

errors='coerce'
会将这些非数值转换为
Nan
而不是抛出错误。然后删除
Nan

# drops Nan values in `winterman` column
test.dropna(subset=['wintermean'], inplace=True)
© www.soinside.com 2019 - 2024. All rights reserved.