I want to add a new category into my existing column based on some conditions
Trial
df.loc[df['cat'] == 'woman','age'].max()-df.loc[df['cat'] == 'man','age'].max().apend{'cat': 'first_child', 'age': age}
import pandas as pd
d = {'cat': ['man1','man', 'woman','woman'], 'age': [30, 40, 50,55]}
df = pd.DataFrame(data=d)
print(df)
cat age
man 30
man 40
woman 50
woman 55
output required:
cat age
man 30
man 40
woman 50
woman 55
first_child 15
sec_child 10
Its possible by transpose but actual data is very complex
df.transpose()
cat man man woman woman
age 30 40 50 55
---looking for solution in rows amend----