I'm pretty new to python and pandas. I have a dataframe with columns that hold the number of seedlings for a particular size class:
Plot Location Year Species 6-12_in 12-24_in 24-54_in GreaterThan_54_in
1 VMU 2015 BC 3 8
What I want to do is convert that dataframe to a format like this, where each size class (6-12_in, 12-24_in, 24-54_in, and GreaterThan_54_in) are numbered 1-4 and put into Size_Class/Count columns like this:
Plot Location Year Species Size_Class Count
1 VMU 2015 BC 1 3
1 VMU 2015 BC 3 8
I arbitrarily named the columns from dataframe 1, so
6-12_in =1
12-24_in =2
24-54_in=3
GreaterThan_54_in=4
I could easily write this looping through each row and building the new dataframe with if statements, but I feel like there must be a map/apply solution that is more efficient? I found this thread, which is kind of similar, but I'm not sure how to easily map the column names and make multiple rows? Merge multiple column values into one column in python pandas
Any help to get started is appreciated- thank you!