I'm brand new to python and data science, and I have a dataframe which is
WellID x y rho1 rho2 rho3 ... rho5 dep1 dep2 dep3 dep4 dep5
0 1 5 3 44 67 34 ... 65 0 1 2 3 4
1 2 1 6 87 67 67 ... 34 0 1 2 3 4
2 3 6 3 65 34 34 ... 65 0 1 2 3 4
3 4 5 6 98 45 67 ... 32 0 1 2 3 4
4 5 3 3 34 65 34 ... 65 0 1 2 3 4
5 6 4 5 67 98 98 ... 34 0 1 2 3 4
After melting the df, my product is
df.melt(['WellID','x','y'])
WellID x y variable value
0 1 5 3 rho1 44
48 1 5 3 dep4 3
42 1 5 3 dep3 2
36 1 5 3 dep2 1
6 1 5 3 rho2 67
30 1 5 3 dep1 0
24 1 5 3 rho5 65
54 1 5 3 dep5 4
12 1 5 3 rho3 34
18 1 5 3 rho4 67
43 2 1 6 dep3 2
37 2 1 6 dep2 1
31 2 1 6 dep1 0
49 2 1 6 dep4 3
19 2 1 6 rho4 34
.
.
.
.
and so forth.
However, what I need is a df where I have a 'dep' and 'rho' column which are correlated to the specific 'WellID' and numeric value of dep and rho, ie
This is the output I'm looking for
WellID x y Dep Rho
1 1 5 dep1 rho1
1 1 5 dep2 rho2
1 1 5 dep3 rho3
1 1 5 dep4 rho4
2 5 3 dep1 rho1
2 5 3 dep2 rho2
2 5 3 dep3 rho3
and so on, where the value in the depth and rho column are the corresponding values.
I've played around with pd.pivot, .stack() and .unstack() and some other stuff, but pd.melt() is the closest I've gotten.
It is probably worth noting that the 'dep' values are continuous through the data, but the 'rho' values are unique to each point.
Thanks