numpy 如何从一个嵌套框中绘制值?

7z5jn7bk  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(93)

我有一个名为test的数组,其中包含了一个城市自1951年以来的冬季温度。我想绘制包含在名为wintermean的列中的温度,但当我尝试使用plt.plot(test.wintermean.values)时,我得到以下错误:TypeError:无法将系列转换为<class 'float'>。以下是testwintermeantest.wintermean.values的外观:

如何绘制温度数据?

zi8p0yeb

zi8p0yeb1#

看起来你的DataFrame只有一行,列值是pandas.Series。要绘制该系列,请尝试:

test["wintermean"].iloc[0].plot()
iyzzxitl

iyzzxitl2#

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

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)

相关问题