I am a bit confused about how to use melt
or stack
correctly in order to transform my dataframe.
Currently have a dataframe which looks as follows:
My objective is to transform this data frame, (probably using melt
or stack
), and I'm having some trouble doing so. My objective is to have my dataframe look like this:
My data is currently stored in a dict
:
{'K_T1': [84.51865079365093,
84.51865079365093,
83.80912698412698,
83.80912698412698,
86.56468253968255,
86.56468253968255],
'K_T2': [77.26309523809515,
77.26309523809515,
77.57777777777771,
77.57777777777771,
77.09999999999992,
77.09999999999992],
'Z_T1': [83.80912698412698,
83.80912698412698,
86.61111111111107,
86.61111111111107,
87.81746031746032,
87.81746031746032],
'Z_T2': [77.57777777777771,
77.57777777777771,
75.8619047619048,
75.8619047619048,
74.79007936507927,
74.79007936507927]}
Pseudocode:
- Convert my
dict
to a dataframe:K_Z_Averages_df = pd.DataFrame.from_dict(K_Z_Averages)
- Add a column, for
Part Name
. - Identify if the initial column name has T1 or T2 listed and place it into the correct column,
T1
orT2
usingmelt
orstack
.
Thanks for any support which can be offered!