Appearance
Overview
You can directly import pandas for common data analysis
- Create a pandas dataframe
python
import pandas as pd
df = pd.DataFrame({'id': [1,2,3,4], 'val': ['a', 'b', 'c', 'd']})
df
id | val | |
---|---|---|
0 | 1 | a |
1 | 2 | b |
2 | 3 | c |
3 | 4 | d |
- 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')
User | 2020-01-01 | 2021-01-01 |
---|---|---|
Jerry | 5000 | 2000 |
John | 1000 | 3000 |