(Code at the bottom)\
price_a price_b companies
2019-01-03 25 50 A
2019-03-03 30 60 B
2019-03-19 23 46 A
Let us say my dataframe above is named 'df'. I would like to extract the entire rows for Company 'A' under the column 'companies'. I am thinking how I could implement the if-statement:
if df['companies'] == 'A':\
print.....
CODE for df:
p = [25,30,23]
dates = ['2019-01-03', '2019-03-03', '2019-03-19']
df = pd.DataFrame(p, index = dates, columns = ['price_a'])
df['price_b'] = df['price_a'] * 2
df.loc['2019-01-03', 'companies'] = 'A'
df.loc['2019-03-03', 'companies'] = 'B'
df.loc['2019-03-19', 'companies'] = 'A'
print(df)
Aucun commentaire:
Enregistrer un commentaire