」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 在Pandas中如何將年份和季度列合併為一個週期列?

在Pandas中如何將年份和季度列合併為一個週期列?

發佈於2025-04-30
瀏覽:623

How Can I Combine Year and Quarter Columns into a Single Period Column in Pandas?
pandas data frame thing commans date lay neal and pree pree'和pree pree pree”,季度

2000 q2

這個目標是通過組合“年度”和“季度”列來創建一個新列,以獲取以下結果:

[python中的concatenate string列,一個人可以直接使用“ operator:operator:operator:

注意到,在Python 3中,有必要在執行串聯之前將“年”列轉換為字符串,如上面使用Astype(str)(str)所示的示例所示。 results.


Additional Options:



For concatenating multiple string columns, Pandas provides a convenient agg function:

df['period'] = df[['Year', 'quarter', ...]].agg('-'.join, axis = 1)[&& && pre> [&& && &&&&&&&&&&&&&&&&&&&&&&' - '代表用於連接列值的隔板字符串。處理多個字符串列時,此方法特別有用。

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3