I have a pandas DataFrame like so:
import pandas as pd
df = pd.DataFrame({
'date': ['2001-01-01', '2001-02-01', '2001-01-01', '2001-02-01', '2001-02-01', '2001-03-01'],
'product': ['A', 'A', 'B', 'B', 'C', 'C'],
'value': [2.5, 2.6, 1.5, 1.6, 3.2, 3.4]
})
df
date product value
0 2001-01-01 A 2.5
1 2001-02-01 A 2.6
2 2001-01-01 B 1.5
3 2001-02-01 B 1.6
4 2001-02-01 C 3.2
5 2001-03-01 C 3.4
I want to use a for loop to loop over all unique values of product
and create separate dataframes with only rows pertaining to that product
. The final output I want is below:
A
date product value
0 2001-01-01 A 2.5
1 2001-02-01 A 2.6
B
2 2001-01-01 B 1.5
3 2001-02-01 B 1.6
C
4 2001-02-01 C 3.2
5 2001-03-01 C 3.4