亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

拆分列中的行并為數據框繪制圖形。Python

拆分列中的行并為數據框繪制圖形。Python

精慕HU 2022-01-05 20:16:05
我的數據集包含days和hrs的數據time slot              hr_slot       location_point2019-01-21 00:00:00       0              342019-01-21 01:00:00       1              5642019-01-21 02:00:00       2              448 2019-01-21 03:00:00       3              46....2019-01-22 23:00:00       23             782019-01-22 00:00:00       0              342019-01-22 01:00:00       1              1652019-01-22 02:00:00       2              65 2019-01-22 03:00:00       3              156....2019-01-22 23:00:00       23             78數據集持續 7 天。即 7*24 行。如何繪制上述數據集的圖形。hr_slot on the X axis : (0-23 hours)loaction_point on Y axis : (location_point)and each day should have different color on the graph: (Day1: color1, Day2:color2....)
查看完整描述

1 回答

?
www說

TA貢獻1775條經驗 獲得超8個贊

考慮旋轉第一您的數據:


# Create normalized date column

df['date'] = df['time slot'].dt.date.astype(str)


# Pivot

piv = df.pivot(index='hr_slot', columns='date', values='location_point')

piv.plot()

更新

要過濾繪制的日期,請使用loc或iloc:


# Exclude first and last day    

piv.iloc[:, 1:-1].plot()


# Include specific dates only

piv.loc[:, ['2019-01-21', '2019-01-22']].plot()

使用替代方法pandas.crosstab:


(pd.crosstab(df['hr_slot'],

             df['time slot'].dt.date,

             values=df['location_point'],

             aggfunc='sum')

 .plot())


查看完整回答
反對 回復 2022-01-05
  • 1 回答
  • 0 關注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號