1

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
  • 2
    Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Sep 04 '19 at 12:31
  • Reconsider appending to a Series as appending to a DataFrame (i.e., dictionary of equal length Series) leads to the inefficient [quadratic copy](https://stackoverflow.com/a/36489724/1422451). – Parfait Sep 04 '19 at 14:26

1 Answers1

0

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()
Scott Boston
  • 147,308
  • 15
  • 139
  • 187