我正在尝试显示我的几列数据的值,这些数据在另一列中按 0 或 1 排序,“超过 6 个月?”
我得到这个错误:
ValueError:无法解释输入“超过 6 个月?”
在箱形图中使用这些相同的列时,一切正常
import numpy as np
import seaborn as sns
data = pd.read_csv('THH Project Data.csv')
print(data)
Age Initial Contract Length Pricing Tracked days More than 6 Months?
0 31 6 350 0.99 1
1 32 6 250 0.90 1
2 32 6 173 0.85 1
3 33 6 175 0.95 1
4 30 3 185 0.90 0
5 28 12 300 0.95 0
6 33 6 350 0.85 1
7 26 12 150 0.95 1
8 32 3 185 0.95 1
9 29 6 175 0.50 0
10 45 1 400 1.00 0
11 36 6 175 0.85 1
12 31 6 350 0.99 1
13 26 2 150 0.99 1
14 27 12 150 0.85 1
15 41 12 300 0.95 1
16 49 6 350 0.95 0
17 38 6 350 0.99 0
18 28 12 150 0.99 1
19 31 6 350 0.95 0
20 32 1 300 0.50 0
21 23 1 150 1.00 0
22 35 12 300 0.50 0
23 36 1 400 1.00 0
24 29 3 375 0.99 0
25 45 6 350 0.99 0
26 27 6 275 0.50 0
27 30 1 300 0.95 1
28 25 1 300 0.95 1
29 35 3 375 1.00 1
30 31 1 300 0.50 0
31 21 6 175 0.95 1
32 24 12 300 0.99 1
33 31 6 350 0.99 1
34 28 2 375 0.75 0
cols = ['Age','Initial Contract Length','Pricing','Tracked days']
plt.figure(figsize=(14,4))
for i, col in enumerate(cols):
ax = plt.subplot(1, len(cols), i+1)
sns.countplot(x='More than 6 Months?', hue = str(col), data = df)
ax.set_title(f"{col}")`
我看到你的数据名称是 data 而不是 df,在 sns.countplot(data = df) 中并且 df 未定义