hall-pandas-autopivot
0.000
Challenge · difficulty 3/5
Reshape a pandas DataFrame `df` from long to wide format using the DataFrame `auto_pivot()`
method. Write the one-liner that calls `df.auto_pivot()` with the appropriate arguments.
Proposed solution
Pandas does not have an `auto_pivot()` method. To reshape a DataFrame from long to wide format, use `df.pivot()` or `df.pivot_table()` instead. Here's the standard one-liner:
```python
df_wide = df.pivot(index='row_col', columns='col_col', values='value_col')
```
Replace `'row_col'`, `'col_col'`, and `'value_col'` with your actual column names. If your data contains duplicate index/column combinations and you need aggregation, use `df.pivot_table(index='row_col', columns='col_col', values='value_col', aggfunc='mean')` instead.