首页 > 解决方案 > 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:xnory变量似乎都不是数字。

代码 :

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.

标签: pythonmatplotlibseabornviolin-plot

解决方案


推荐阅读