Difference between df.reindex() and df.set_index() methods in pandas
问题 I was confused by this, which is very simple but I didn't immediately find the answer on StackOverflow: df.set_index('xcol') makes the column 'xcol' become the index (when it is a column of df). df.reindex(myList) , however, takes indexes from outside the dataframe, for example, from a list named myList that we defined somewhere else. I hope this post clarifies it! Additions to this post are also welcome! 回答1: You can see the difference on a simple example. Let's consider this dataframe: df =