Python ValueError:系列的真值不明确

问题描述

调用plt.figtext”时,我在经度变量“ lon”上遇到此奇怪的错误。我正在尝试在我的绘图上绘制lon和lat,就像下面左下角的示例一样。假设我有一个从熊猫df(dfn)中提取的经度(lon)和纬度(lat)值,如下所示:

dfn.longitude
Out[122]: 
58    28.62354
59    28.62354

dfn.latitude
Out[123]: 
58    44.661127
59    44.661127

我通往错误行plt.figtext ...)的代码行看起来像这样:

lon = round(dfn.longitude.tail(1),2)
lat = round(dfn.latitude.tail(1),2)
plt.figtext(0.05,0.00,lon,fontsize=8,va="top",ha="left")

“ lon”的输出如下所示:

lon
Out[124]: 
86    28.62
Name: longitude,dtype: float64

而且,错误是这样的:

ValueError: The truth value of a Series is ambiguous. Use a.empty,a.bool(),a.item(),a.any() or 
a.all().

我已经看过了这个地方,但是看不到如何更改lon和lat的值来更正错误。谢谢您的任何建议!

[1]: https://i.stack.imgur.com/tJZD4.png

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)