I have a dataframe with two columns A and B,
import pandas as pd
import numpy as np
df = pd.DataFrame({
'A':[1,3,7,19,80,120,14,2],
'B':['years','years','months','months','days','days','months','years',]
})
I want change the value of with uniform measurement of 'years' as in:
df = pd.DataFrame({
'A':[1,3,0.58,1.58,0.22,0.33,1.17,2],
'B':['years','years','years','years','years','years','years','years']
})
I tried the with following code but I get (ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().)
for x in df.B:
if x== 'days':
df['A']=df['A'].div(365).round(2)
elif x== 'months':
df['A']=df['A'].div(12).round(2)
else:
pass