Hi there I have a data set look like df1 below and I want to make it look like df2 using pandas. I have tried to use pivot and transpose but can't wrap my head around how to do it. Appreciate any help!
Asked
Active
Viewed 76 times
-1
-
3Paste the DF as code instead of images please. You can look at how they've pasted it here : https://stackoverflow.com/questions/67394649/recalculate-mean-considering-each-count – Shubham Periwal May 05 '21 at 03:46
-
3Have you tried `pandas.pivot_table()`? https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.pivot.html#pandas.DataFrame.pivot – Gusti Adli May 05 '21 at 03:50
1 Answers
0
This should do the job
df.pivot_table(index=["AssetID"], columns='MeterName', values='MeterValue')
index: Identifier
columns: row values that will become columns
values: values to put in those columns
I often have the same trouble: https://towardsdatascience.com/reshape-pandas-dataframe-with-pivot-table-in-python-tutorial-and-visualization-2248c2012a31
This could help next time.

Francisco Pina
- 51
- 2