0

I was losing data on a reindex. I just wanted to make an existing column the index.

So this works:

df_all_maa = df_all_maa.set_index("VERSION_SEQ")

Originally I was doing this:

df_all_maa = df_all_maa.reindex(df_all_maa["VERSION_SEQ"])

I think what was happening was I was only getting values in the resulting dataframe, where the VERSION_SEQ value happened to match the numeric default index, but I would be interested to know what my original incorrect syntax was actually doing.

smackenzie
  • 2,880
  • 7
  • 46
  • 99

1 Answers1

1

reindex is similar to loc, but allowing non-existing indexes. reindex creates a row with nan values whence there are non-existing indexes, while loc would throw an error.

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74