乔小乔9S 2022-01-18 15:05 采纳率: 60%
浏览 428

python warning: merge error in future version

代码非常简单 在合并列表的时候

resultP = pd.merge(outputP0, outputP, left_index = True, right_index = True, how = 'outer')

在跑程序的时候,会有一个FutureWarning:
Passing 'suffixes' which cause duplicate columns {'para_x'} in the result is deprecated and will raise a MergeError in a future version.

好像不至于会影响最终的结果,但是能够不要有这串东西

  • 写回答

3条回答 默认 最新

  • CSDN专家-HGJ 2022-01-18 17:05
    关注

    合并列表中的数据框,可使用concat,避免弃用警告。参考示例:

    import pandas as pd 
    import numpy as np
    df1 = pd.DataFrame({'key': ['A', 'B', 'C', 'D'], 'value': np.random.randn(4)})
    df2 = pd.DataFrame({'key': ['B', 'D', 'E', 'F'], 'value': np.random.randn(4)})
    df3 = pd.DataFrame({'key': ['A', 'C', 'E', 'F'], 'value': np.random.randn(4)})
    df_list = [df1, df2, df3]
    s = pd.concat([x.set_index('key') for x in df_list],axis = 1,keys=range(len(df_list)))
    s.columns = s.columns.map('{0[1]}_{0[0]}'.format)
    s = s.reset_index()
    print(s)
    

    如有帮助,请点采纳。

    评论

报告相同问题?

问题事件

  • 创建了问题 1月18日