Skip to content

Instantly share code, notes, and snippets.

@karanjagota
Created July 5, 2019 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karanjagota/ad01cf4f76ec146e4bc69c1304a25364 to your computer and use it in GitHub Desktop.
Save karanjagota/ad01cf4f76ec146e4bc69c1304a25364 to your computer and use it in GitHub Desktop.
gist for medium blogs ..
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