The Pandas set index function was a mystery to me when I started. In this video you will quickly understand how to set and reset indexes like a boss.
We start by creating some sample data and placing it into a dataframe. It's important to note that everytime you create a Pandas dataframe, you are also creating an index. The default index is numeric. It starts with zero for the first row and increments by one until it gets to the end of your dataframe.
What is the index really used for?
1) For slicing and dicing
2) For plotting
3) Groupby operations make use of the index
The video then continues and shows you how to set a column as the index. We used the key column as the index. There was also examples on how to verify or how to look for the index. We have the .index() and the .info() methods. Both tell you in different ways what your index is. We didn't touch on the index name, but that is an attribute that you can change if needed.
If you wanted to remove the index, that is also possible. The .reset_index() method was introduced and a simple example given. Note that if the index name was changed at some point, resetting the index will not revert back to the old column name.
Lastly plotting was touched upon. Since Pandas visualizations usually grab the x axis labels from the index, a few examples were given to show you how plots are affected by the index. Bottom line here was that if you want more descriptive plots, make sure the index is populated appropriately.
Смотрите видео How I Use the Pandas Set Index Function онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Learn Pandas 02 Декабрь 2018, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 2,956 раз и оно понравилось 28 людям.