Skip to content

Overview

You can directly import pandas for common data analysis

  1. Create a pandas dataframe
python
import pandas as pd
df = pd.DataFrame({'id': [1,2,3,4], 'val': ['a', 'b', 'c', 'd']})
df
idval
01a
12b
23c
34d
  1. Pivot a data frame:
python
df = pd.DataFrame({'User': ['John', 'John', 'Jerry', 'Jerry'], 'Date': ['2020-01-01', '2021-01-01', '2020-01-01', '2021-01-01'], 'Balance': [1000, 3000, 5000, 2000]})
df.pivot('User', 'Date', 'Balance')
User2020-01-012021-01-01
Jerry50002000
John10003000