我有一个数据集,我不得不变成一个数据框。这些数据框有5列(性别,组,课程,英语成绩,最终分数)列组有5个独特的组(组a,组B.组e)。我需要的是绘制一个直方图超过组a的英语分数,并设置箱数为20。
g6ll5ycj1#
下面是一个示例代码:
import pandas as pdimport matplotlib.pyplot as plt# assuming you have already converted your data to a data frame named dfdf = df.reset_index()# filter the rows for group agroup_a = df[df['group'] == 'group a']# plot the histogram for english_score with 20 binsplt.hist(group_a['english_score'], bins=20)plt.title('English Score Histogram for Group A')plt.xlabel('English Score')plt.ylabel('Frequency')plt.show()
import pandas as pd
import matplotlib.pyplot as plt
# assuming you have already converted your data to a data frame named df
df = df.reset_index()
# filter the rows for group a
group_a = df[df['group'] == 'group a']
# plot the histogram for english_score with 20 bins
plt.hist(group_a['english_score'], bins=20)
plt.title('English Score Histogram for Group A')
plt.xlabel('English Score')
plt.ylabel('Frequency')
plt.show()
字符串这段代码首先过滤数据框中与组a对应的行,然后使用pandas库绘制组a的“english_score”列的直方图,其中包含20个bin,最后使用matplotlib库显示直方图。您需要编写的实际代码可能会因数据的结构及其在数据框中的存储方式而异。话虽如此,这个示例应该让您给予如何处理这个问题的一般概念。
1条答案
按热度按时间g6ll5ycj1#
下面是一个示例代码:
字符串
这段代码首先过滤数据框中与组a对应的行,然后使用pandas库绘制组a的“english_score”列的直方图,其中包含20个bin,最后使用matplotlib库显示直方图。
您需要编写的实际代码可能会因数据的结构及其在数据框中的存储方式而异。话虽如此,这个示例应该让您给予如何处理这个问题的一般概念。