Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何解决值错误:真值_Python_Pandas_Matplotlib_Python 3.7 - Fatal编程技术网

Python 如何解决值错误:真值

Python 如何解决值错误:真值,python,pandas,matplotlib,python-3.7,Python,Pandas,Matplotlib,Python 3.7,我有一个数据文件,使用pandas从中选择数据列。然后,我使用这些列中的数据,使用matplotlib将其绘制在散点图上,但我得到一个错误,它说:ValueError:序列的真值是不明确的。使用a.empty、a.bool()、a.item()、a.any()或a.all() 我已经在StackOverflow上搜索过这个问题,但它们与数据打印无关 # Getting data from column that user selects variable1 = location_data.ilo

我有一个数据文件,使用pandas从中选择数据列。然后,我使用这些列中的数据,使用matplotlib将其绘制在散点图上,但我得到一个错误,它说:ValueError:序列的真值是不明确的。使用a.empty、a.bool()、a.item()、a.any()或a.all()

我已经在StackOverflow上搜索过这个问题,但它们与数据打印无关

# Getting data from column that user selects
variable1 = location_data.iloc[0:-1, columnPosition1]
variable2 = location_data.iloc[0:-1, columnPosition2]

# Converting data from variable1 and 2 to float and storing in list called x & y
for xValue in variable1:
    x.append(float(xValue))

for yValue in variable2:
    y.append(float(yValue))


# x and y are lists which hold data from excel file
# Error begins here
plt.scatter(x, y, marker='o')
plt.xlabel(variable1, fontsize = 15)
plt.ylabel(variable2, fontsize = 15)
plt.title('A graph of ' + variable1 + ' and ' + variable2)
回溯(最近一次呼叫最后一次):
文件“F:\Computer Science\NEA\Code\Coursework.py”,第115行,在
绘图数据(变量1、变量2)
文件“F:\Computer Science\NEA\Code\Coursework.py”,第96行,在绘图数据中
plt.xlabel(变量1,fontsize=15)
xlabel格式的文件“C:\Users\Naima\AppData\Local\Programs\Python37-32\lib\site packages\matplotlib\pyplot.py”,第3065行
xlabel,fontdict=fontdict,labelpad=labelpad,**kwargs)
文件“C:\Users\Naima\AppData\Local\Programs\Python\Python37-32\lib\site packages\matplotlib\axes\\u axes.py”,第265行,在集合标签中
返回self.xaxis.set_label_text(xlabel、fontdict、**kwargs)
文件“C:\Users\Naima\AppData\Local\Programs\Python\Python37-32\lib\site packages\matplotlib\axis.py”,第1564行,在集合标签文本中
self.label.set_文本(标签)
文件“C:\Users\Naima\AppData\Local\Programs\Python\Python37-32\lib\site packages\matplotlib\text.py”,第1191行,在set\u text中
如果s!=self.\u文本:
文件“C:\Users\Naima\AppData\Local\Programs\Python\Python37-32\lib\site packages\pandas\core\generic.py”,第1478行,非零__
.format(self.\uuuuuu class.\uuuuuuu.\uuuuuu name.\uuuuuuuuu))
ValueError:序列的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all()。
您正在将数据系列设置为标签字符串:

由于
plt.xlabel
plt.ylabel
不检查标签的类型,因此当试图将序列视为字符串时,它们会阻塞

改为将显式字符串设置为标签:

plt.xlabel("The X Axis", fontsize = 15)

这是一个常见的错误。你能把实际的错误信息和部分或全部的数据帧复制粘贴到你的问题中吗?拉希姆,这是一本很好的读物,可以帮助你得到你需要的答案。你确定错误确实发生在代码的这一部分吗?@run out我已经做了你建议的编辑。您需要进一步的代码或信息吗?@MisterMiyagi我已粘贴在错误消息中,并对错误开始的位置进行了注释。你还需要什么吗?
plt.xlabel(variable1, fontsize = 15)
plt.xlabel("The X Axis", fontsize = 15)