python - ValueError:x 和 y 变量似乎都不是数字
问题描述
目前正在尝试从seaborn
包装中制作小提琴情节。但总是得到提到的错误。
ValueError: min() arg 是一个空序列
代码:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
table = pd.read_excel("path to the file")
fig, ax = plt.subplots()
fig.set_size_inches(14,5)
df = pd.DataFrame(columns =['Squad','Age'])
df = df.explode('Squad')
df['Squad'] = df['Squad'].astype('float')
ax = sb.violinplot(data = df, x="Squad", y="Age")
plt.xticks(rotation=65)
plt.show()
如果有人可以提供帮助将不胜感激。谢谢。
编辑:犯了一个愚蠢的错误。df 中没有包含表格。但在包括之后,得到一个新的错误。当我添加 时.explode()
,得到了无法将其从字符串转换为浮点数的错误。
ValueError:
x
nory
变量似乎都不是数字。
代码 :
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
table = pd.read_excel("G:/Others/football analytics/ageepl.xlsx")
fig, ax = plt.subplots()
fig.set_size_inches(14,5)
df = pd.DataFrame(table, columns =['Squad','Age'])
ax = sb.violinplot(data = df, x="Squad", y="Age")
plt.xticks(rotation=65)
plt.show()
错误 :
Traceback (most recent call last):
File "G:\Others\football analytics\python\age_violin.py", line 11, in <module>
ax = sb.violinplot(data = df, x="Squad", y="Age")
File "C:\Users\MAHE\anaconda3\lib\site-packages\seaborn\categorical.py", line 2384, in violinplot
plotter = _ViolinPlotter(x, y, hue, data, order, hue_order,
File "C:\Users\MAHE\anaconda3\lib\site-packages\seaborn\categorical.py", line 552, in __init__
self.establish_variables(x, y, hue, data, orient, order, hue_order)
File "C:\Users\MAHE\anaconda3\lib\site-packages\seaborn\categorical.py", line 155, in establish_variables
orient = self.infer_orient(x, y, orient)
File "C:\Users\MAHE\anaconda3\lib\site-packages\seaborn\categorical.py", line 354, in infer_orient
raise ValueError(no_numeric)
ValueError: Neither the `x` nor `y` variable appears to be numeric.
解决方案
推荐阅读
- excel - Excel日期舍入计算
- c# - 无法从“void”转换为 System.Threading.Tasks.Task
- tensorflow - 自动将类似 Tensorboard 的损失图保存到图像文件中
- c# - C# - System.ArgumentOutOfRangeExceptionSpecified 参数超出有效值范围
- css - 具有未定义宽度的浮动段落
- java - 在方法中使用字符串的值
- php - Wordpress 登录链接不起作用
- javascript - 如何将数字四舍五入到最接近的比例/因子数
- android - 套接字 - 如何?
- angular - 如何将项目 angular4 集成到另一个项目 angular4