python 合並列表問題“list indices must be integers or slices, not list"


 

有一個列表的列表,每個列表包含一個公共列,A,B,用作索引,如下所示

df_list=[[df1], [df2],[df3], [df4], [df5, df6]]

我想根據所有數據幀中的公共列A、B將數據幀合並到單個數據幀中

我試過了pd.concat(df_list),但不起作用,產生錯誤如下:

 list indices must be integers or slices, not list

有沒有辦法做到這一點

 

 

方法:

試着簡單地使用類似的方法:

dfs = [df1, df2, df3, ... etc]

print(pd.concat(dfs))

注意,在將dfs存儲在列表中時,不應將其保存在第二個列表中,pd.concat獲取dfs列表。

 

原文:

python 合並列表問題“list indices must be integers or slices, not list”

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM