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

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

為什么 pd.reset_index 將 Series 轉換為 DataFrame

為什么 pd.reset_index 將 Series 轉換為 DataFrame

慕工程0101907 2023-12-26 15:10:03
我有以下數據:接下來我執行:讓我困惑的是reset_index()將Series更改為DataFrame。這是為什么?看到pandas文檔后,我預計會出現錯誤,因為reset_index僅適用于DataFrame:預先感謝您為我解決了這個問題。
查看完整描述

3 回答

?
心有法竹

TA貢獻1866條經驗 獲得超5個贊

您正在使用Series.reset_index。所以要檢查的正確頁面是:

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.reset_index.html


查看完整回答
反對 回復 2023-12-26
?
德瑪西亞99

TA貢獻1770條經驗 獲得超3個贊

根據Series Docs

Series 是一個一維標記數組,能夠保存任何類型的數據。

當您執行 a 時reset_index(),會向其中添加另一列,因此它不再是one-dimensionalSeries,而是變成了dataframe。

reset_index docs

生成一個新的 DataFrame 或 Series 并重置索引。

希望這能消除你的疑慮。


查看完整回答
反對 回復 2023-12-26
?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

幫助Series.reset_index是


reset_index(self, level=None, drop=False, name=None, inplace=False)

? ? Generate a new DataFrame or Series with the index reset.

? ??

? ? This is useful when the index needs to be treated as a column, or

? ? when the index is meaningless and needs to be reset to the default

? ? before another operation.


? ? ...

文檔drop是


? ? drop : bool, default False

? ? ? ? Just reset the index, without inserting it as a column in

? ? ? ? the new DataFrame.

默認情況下,該系列將轉換為具有新索引的數據幀。但是使用 時drop=False,會返回帶有重置索引的系列。這對我來說似乎是倒退的 - 默認重置系列索引將是“reset_index”恕我直言的更自然的結果。


查看完整回答
反對 回復 2023-12-26
  • 3 回答
  • 0 關注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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