I have a pandas df of data stripped from a pdf. I have already done some considerable wrangling to get it to this point. There are about 100 chemical concentrations at about 10 sites, and in separate rows, a lab note for each of them denoting info from the tests corresponding to each site. I would like to add the unit (various units) into the column name and move the lab note (a,b,c,d,e in example, vary in my data) into the row for its respective location. Please see image below.
current df vs desired df layout
Previously the lab note was in the row directly under its respective lab test – after an outer join with a df of the coordinates of the test sites, it was rearranged as seen in the example I posted.
I am inexperienced with loops, and certainly need a loop solution due to the number of columns in my data.
Thank you.
Attempted to add unit to column name using
df.rename(columns={‘chem1’: ‘chem1’+df.chem1.iloc(index of units row),repeat ad infinitum}, inplace=True)
Do not know where to start with loops for either problem
rlep is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.