pandas three-way joining multiple dataframes on columns

前端 未结 11 1780
醉梦人生
醉梦人生 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 08:56

    There is another solution from the pandas documentation (that I don't see here),

    using the .append

    >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
       A  B
    0  1  2
    1  3  4
    >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'))
       A  B
    0  5  6
    1  7  8
    >>> df.append(df2, ignore_index=True)
       A  B
    0  1  2
    1  3  4
    2  5  6
    3  7  8
    

    The ignore_index=True is used to ignore the index of the appended dataframe, replacing it with the next index available in the source one.

    If there are different column names, Nan will be introduced.

提交回复
热议问题