SNIPPET
3 Upvotes

Pivoting Pandas Dataframes

Python
Data Preprocessing

Creates a new DataFrame that pivots the orders Dataframe so the rows are product IDs, the columns are order dates and the cell values are units sold. Any NAs are filled with 0s.

units_by_day = orders.groupby(['Order_Date','ProductID'],as_index=False)['units'].sum()
units_by_day_pivot = units_by_day.pivot(index='ProductID', columns='Order_Date', values='units').reset_index()
units_by_day_pivot.fillna(0, inplace=True)

By analyseup - Last Updated Nov. 24, 2020, 5:59 p.m.

COMMENTS
RELATED SNIPPETS
SparkSession instantiate
Python
Data Preprocessing

2
Converting Data Types
Python
Data Preprocessing

Data-cleaning

2
Data Minification
Python
Data Preprocessing

Cleaning

2
Search Snippets by Tag: