pandas three-way joining multiple dataframes on columns

前端 未结 11 1944
醉梦人生
醉梦人生 2020-11-22 08:35

I have 3 CSV files. Each has the first column as the (string) names of people, while all the other columns in each dataframe are attributes of that person.

How can

11条回答
  •  我在风中等你
    2020-11-22 09:10

    This can also be done as follows for a list of dataframes df_list:

    df = df_list[0]
    for df_ in df_list[1:]:
        df = df.merge(df_, on='join_col_name')
    

    or if the dataframes are in a generator object (e.g. to reduce memory consumption):

    df = next(df_list)
    for df_ in df_list:
        df = df.merge(df_, on='join_col_name')
    

提交回复
热议问题