1 回答

TA貢獻1775條經驗 獲得超8個贊
有了額外的給定信息,我做了這個。希望你喜歡它!
import pandas as pd
import matplotlib.pyplot as plt
plt.close('all')
df=pd.read_csv('https://query.data.world/s/djx5mi7dociacx7smdk45pfmwp3vjo',
encoding='unicode_escape')
df=df.groupby(['Year','GenArea'])['Taught'].sum().to_frame(name=
'Courses').reset_index()
aux1=df.duplicated(subset='GenArea', keep='first').values
aux2=df.duplicated(subset='Year', keep='first').values
n=len(aux1);year=[];courses=[]
for i in range(n):
if not aux1[i]:
courses.append(df.iloc[i]['GenArea'])
if not aux2[i]:
year.append(df.iloc[i]['Year'])
else:
continue
del aux1,aux2
df1=pd.DataFrame(index=year)
s=0
for i in range(len(courses)):
df1[courses[i]]=0
for i in range(n):
string=df.iloc[i]['GenArea']
if any(df1.iloc[s].values==0):
df1.at[year[s],string]=df.iloc[i]['Courses']
else:
s+=1
df1.at[year[s],string]=df.iloc[i]['Courses']
del year,courses,df
df1=df1[df1.columns[::-1]]
df1.plot.area(legend='reverse')
添加回答
舉報