How do I print each asset in this dataframe (['Asset A' 'Asset B' 'Asset C'])? I believe the my syntax is incorrect.
import pandas as pd
df = pd.DataFrame({
'date': ['2019-01-01','2019-01-01','2019-01-01',
'2019-02-01','2019-02-01','2019-02-01',
'2019-03-01','2019-03-01','2019-03-01',
'2019-04-01','2019-04-01','2019-04-01',
'2019-05-01','2019-05-01','2019-05-01'],
'Asset': ['Asset A', 'Asset B', 'Asset C', 'Asset A', 'Asset B', 'Asset C',
'Asset A', 'Asset B', 'Asset C', 'Asset A', 'Asset B', 'Asset C',
'Asset A', 'Asset B', 'Asset C',],
'Monthly Value': [200, 800, 400, 400, 300, 600, 400, 400, 900,
300, 600, 400, 200, 100, 200],
'Indicator': [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0]
})
print(df.sort_values(by=['Asset']))
date Asset Monthly Value Indicator
0 2019-01-01 Asset A 200 0
3 2019-02-01 Asset A 400 0
6 2019-03-01 Asset A 400 0
9 2019-04-01 Asset A 300 0
12 2019-05-01 Asset A 200 1
1 2019-01-01 Asset B 800 0
4 2019-02-01 Asset B 300 0
7 2019-03-01 Asset B 400 1
10 2019-04-01 Asset B 600 0
13 2019-05-01 Asset B 100 0
2 2019-01-01 Asset C 400 0
5 2019-02-01 Asset C 600 0
8 2019-03-01 Asset C 900 0
11 2019-04-01 Asset C 400 1
14 2019-05-01 Asset C 200 0
Something is wrong with this loop
asset = df['Asset'].unique()
for asset in df['Asset']:
print(asset)
Desired output should look like this for Assets A, B, and C.
date Asset Monthly Value Indicator
2 2019-01-01 Asset C 400 0
5 2019-02-01 Asset C 600 0
8 2019-03-01 Asset C 900 0
11 2019-04-01 Asset C 400 1
14 2019-05-01 Asset C 200 0