Skip to content

Instantly share code, notes, and snippets.

@karanjagota karanjagota/reshapedf.py Secret
Created Jul 5, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.