第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何將熊貓數(shù)據(jù)框繪制為散點(diǎn)圖?我想我可能弄亂了索引,無法添加新索引?

如何將熊貓數(shù)據(jù)框繪制為散點(diǎn)圖?我想我可能弄亂了索引,無法添加新索引?

嗶嗶one 2021-11-02 19:24:05
我試圖將我的步驟繪制為散點(diǎn)圖,然后最終添加一條趨勢線。我設(shè)法讓它與 df.plot() 一起使用,但它是一個(gè)折線圖。以下是我嘗試過的代碼:import pandas as pdimport matplotlib.pyplot as pltimport numpy as npdata_file = pd.read_csv('CSV/stepsgyro.csv')# print(data_file.head())# put in the correct data typesdata_file = data_file.astype({"steps": int})pd.to_datetime(data_file['date'])# makes the date definitely the index at the bottomdata_file.set_index(['date'], inplace=True)# sorts the data frame by the indexdata_file.sort_values(by=['date'], inplace=True, ascending=True)# data_file.columns.values[1] = 'date'# plot the raw steps data# data_file.plot()plt.scatter(data_file.date, data_file.steps)plt.title('Daily Steps')plt.grid(alpha=0.3)plt.show()plt.close('all')# plot the cumulative steps datadata_file = data_file.cumsum()data_file.plot()plt.title('Cumulative Daily Steps')plt.grid(alpha=0.3)plt.show()plt.close('all')這是它在我的 IDE 上的樣子的屏幕截圖:
查看完整描述

3 回答

?
Smart貓小萌

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊

您已將索引設(shè)置為“日期”列。從那一刻起,不再有“日期”列,因此data_file.date失敗。

兩種選擇:

  1. 不要設(shè)置索引。無論如何似乎不需要排序。

  2. 繪制索引, plt.scatter(data_file.index, data_file.steps)


查看完整回答
反對 回復(fù) 2021-11-02
?
喵喵時(shí)光機(jī)

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊

僅通過查看您的示例,我無法弄清楚為什么會(huì)出現(xiàn)該錯(cuò)誤。但是,我可以提供一個(gè)快速簡便的解決方案來繪制您的數(shù)據(jù):

data_file.plot(marker='.', linestyle='none')


查看完整回答
反對 回復(fù) 2021-11-02
?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

您可以使用df.plot(kind='scatter')避免折線圖。


查看完整回答
反對 回復(fù) 2021-11-02
  • 3 回答
  • 0 關(guān)注
  • 233 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號