Working with Pandas


Recently, I started working on pandas library to automate some excel operations. It is really fun and easy to work with pandas. Hence i have decided to keep adding few stuff related to pandas

Reset index

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html

df.reset_index(inplace=True)


Additionally we want to convert the date column to integer values.




How can we benefit from a MultiIndex? If we take a loot at the data set, we can see that we have for each country the same set of dates. In this case it would make sense to structure the index hierarchically, by having different dates for each country. This is where the MultiIndex comes to play. Now, in order to set a MultiIndex we need to choose these two columns by by setting the index with set_index.

df.set_index(['country', 'date'], inplace=True)

df.head()