【发布时间】:2019-05-06 17:25:03
【问题描述】:
this is some of the data that is located in the excel sheet
我想选择演员阵容中少数族裔人数多于白种人的音乐剧节目(代码中称为“ID”) 一旦确定,我想将所选代码的信息放入一个新的数据框中 只会举行表演,因为它会更容易操纵。在新的数据框中,我想在同一行显示相关种族,以便与观众种族进行比较。然后我试图绘制这些信息。
一般来说,如果该行符合特定的求和标准,我想将特定行中的值相加。该项目中使用的所有数据都位于一个 Excel 工作表中,该工作表转换为 csv 并作为数据框上传。然后,我想完整地绘制演员的价值观,并将演员的种族与观众的种族进行比较。
我正在使用 python,我尝试通过使用 if 语句选择列来删除不需要的数据,以便数据框仅包含少数族裔比白种人多的节目,然后我尝试使用这个情节中的信息。如果我不在计算中使用它们,我不确定是否必须过滤所有不需要的列
import numpy as np
import pandas as pd
#first need to import numpy so that calculations can be made
from google.colab import files
uploaded = files.upload()
# df = pd.read_csv('/content/drive/My Drive/allTheaterDataV2.csv')
import io
df = pd.read_csv(io.BytesIO(uploaded['allTheaterDataV2.csv']))
# need to download excel sheet as csv and then upload into colab so that it can
# be manipulated as a dataframe
# want to select shows(ID) that had more minorities than Caucasians in the cast
# once determined, the selected shows should be placed into a new data frame that
# will only hold the shows and the related ethnicity, and compared to audience ethnicity
# this information should then be plotted
# first we will determine the shows that have a majority ethnic cast
minorcal = list(df)
minorcal.remove('CAU')
minoritycastSUM = df[minorcal].sum(axis=1)
# print(minorcal)
# next, we determine how many people in the cast were Caucasian, so remove all others
caucasiancal = list(df)
# i first wanted to do caucasiancal.remove('AFRAM', 'ASIAM', 'LAT', 'OTH')
# but got the statement I could only have 1 argument so i just put each on their own line
caucasiancal.remove('AFRAM')
caucasiancal.remove('ASIAM')
caucasiancal.remove('LAT')
caucasiancal.remove('OTH')
idrowcaucal = df[caucasiancal].sum(axis=1)
minoritycompare = old.filter(['idrowcaucal','minoritycastSUM'])
print(minoritycompare)
# now compare the two values per line
if minoritycastSUM < caucasiancal:
minoritydf = pd.df.minorcal.append()
# plot new data frame per each show and compare to audience ethnicity
df.plot(x=['AFRAM', 'ASIAM', 'CAU', 'LAT', 'OTH', 'WHT', 'BLK', 'ASN', 'HSP', 'MRO'], y = [''])
# i am unsure how to call the specific value for each column
plt.title('ID Ethnicity Comparison')
# i am unsure how to call the specific show so that only one show is per plot so for now i just subbed in 'ID'
plt.xlabel('Ethnicity comparison')
plt.ylabel('Number of Cast Members/Audience Members')
plt.show()
我想查看具有符合标准的特定节目的数据框,然后是节目的情节,但现在我在如何制定新数据框和 python 中遇到错误,说不能使用 if 语句。[2]
【问题讨论】:
标签: python pandas numpy dataframe