本笔记为阿里云天池龙珠计划Python训练营的学习内容,链接为:https://tianchi.aliyun.com/specials/promotion/aicamppython;
此处内容不多,后续在pandas和numpy路线进一步整理。
州捐款热力图
分析两位总统在各个州的支持热力图
cand_top2 = c_itcont.groupby('CAND_NAME').sum().sort_values('TRANSACTION_AMT',ascending=False).head(2)
state_amt = pd.DataFrame()
for name in cand_top2.index:
df = c_itcont[c_itcont['CAND_NAME']==name]
df = df.groupby(['CAND_NAME', 'STATE']).sum().sort_values('TRANSACTION_AMT',ascending=False).reset_index('CAND_NAME').head(10)
df.drop('CAND_NAME',axis=1, inplace=True)
df.columns = [name]
state_amt = pd.concat([state_amt, df],axis=1)
sns.heatmap(state_amt,cmap='RdBu_r')
捐款额变化趋势
cand_top2 = c_itcont.groupby('CAND_NAME').sum().sort_values('TRANSACTION_AMT',ascending=False).head(2)
cand_amt_time = pd.DataFrame()
for name in cand_top2.index:
df = c_itcont[c_itcont['CAND_NAME']==name]
df = df.groupby(['CAND_NAME', 'TRANSACTION_DT']).sum().reset_index('CAND_NAME')
df.drop('CAND_NAME',axis=1, inplace=True)
df.columns = [name]
cand_amt_time = pd.concat([cand_amt_time, df],axis=1)
cand_amt_time.plot()
|