【发布时间】:2021-07-22 18:55:03
【问题描述】:
我正在使用二进制分类数据集。我想要一个计划,显示第一列显示人们的年龄,下一列显示一年级学生的年龄,第三列显示二年级学生的年龄。请告诉我应该怎么做
age | class
------------
1 | 1
2 | 1
3 | 0
4 | 1
5 | 0
6 | 1
7 | 1
8 | 0
9 | 0
10 | 1
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv (r'test.csv')
firstClassDf = df[df['class'] == '0']
print(firstClassDf.shape)
print(firstClassDf.head())
secondClassDf = df[df['class'] == '1']
print(secondClassDf.shape)
boxplot1 = df.boxplot(column='age')
plt.figure()
boxplot2 = firstClassDf.boxplot(column='age')
plt.figure()
boxplot3 = secondClassDf.boxplot(column='age')
plt.figure()
print(plt.show())
【问题讨论】:
-
您能预览一下 test.csv 吗? df.head() 就足够了
-
@DSteman 是的,当然
-
你想要的输出是什么样的?
-
@DSteman 我已经添加了预期的设计
-
我的数据视图和我上面写的差不多,一栏是人,第二栏是班级。 @paradocslover
标签: python data-science data-mining