Skip to content

Instantly share code, notes, and snippets.

@BioSciEconomist
Created December 6, 2018 01:26
Show Gist options
  • Save BioSciEconomist/862aa7775c1dd588ac602f7ef6b75a2a to your computer and use it in GitHub Desktop.
Save BioSciEconomist/862aa7775c1dd588ac602f7ef6b75a2a to your computer and use it in GitHub Desktop.
Examples of processing data in python
# make a data frame manually
data = {'GARST' :[150,140,145,137,141,145,149,153,157,161],
'PIO':[160,150,146,138,142,146,150,154,158,162],
'MYC':[137,148,151,139,143,120,115,136,130,129],
'DEK':[150,149,145,140,144,148,152,156,160,164],
'PLOT':[1,2,3,4,5,6,7,8,9,10],
'BT': ['Y','Y', 'N','N','N','N','Y','N','Y','Y'],
'RR':['Y','N','Y','N','N','N','N','Y','Y','N'],
'ID':[1,2,3,4,5,6,7,8,9,10]
}
# convert to a data frame
df = pd.DataFrame(data,columns=['ID','GARST','PIO','MYC','DEK','PLOT','BT','RR'])
print(df)
# use melt to convert columns into rows
df2 = pd.melt(df, id_vars=['ID','BT','RR'], var_name='hybrid', value_name='yield')
print(df2) # check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment