-
-
Save karanjagota/ad01cf4f76ec146e4bc69c1304a25364 to your computer and use it in GitHub Desktop.
gist for medium blogs ..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = {'gold':['day1','day2','day3','day4','day5'], | |
'2015':[10,20,30,40,50], | |
'2016':[15,25,35,45,55], | |
'2017':[17,27,37,47,57], | |
'2018':[19,29,39,49,59]} | |
# converting data into dataframe .. | |
horizontal_df = pd.DataFrame(data) | |
# selecting the first 6 rows .. | |
horizontal_df.head() | |
# Reshaping it to a different format .. | |
vertical_df = new_df.melt(id_vars='gold',value_vars=['2015','2016','2017','2018']) # or | |
vertical_df_2 = horizontal_df.melt(id_vars='gold') | |
# selecting the first six rows of new data frame which is in a vertical format ... | |
vertical_df_2.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment