Search code examples
pythonpandasdata-munging

How to append each column of a data-frame to a series in pandas?


why each columns wont append to the series?

id_names = pd.Series()
for column in n_df:
    id_names.append(n_df[column].drop_duplicates(), ignore_index = True)
id_names

Solution

  • You are failing to reassign the result of append back to the series. pd.Series.append is not an inplace method. You need to reassign.

    id_names = pd.Series()
    for column in n_df:
        id_names = id_names.append(n_df[column].drop_duplicates(), ignore_index = True)
    id_names
    

    However, there is a simplier method for doing this task.

    Try:

    n_df.melt()