I have the following dataframe called df containing a variable called Category. I would like to create new_variable with the below mentioned values in Python. How do I do?
df = pd.DataFrame({
'Category': [
'Foreign Stocks', 'Stocks China', 'Stocks',
'Bonds', 'Bonds USA', 'Bonds India'
],
'New_Variable': [
'Stocks', 'Stocks', 'Stocks',
'Bonds', 'Bonds', 'Bonds'
]
})
df
Category New_Variable
0 Foreign Stocks Stocks
1 Stocks China Stocks
2 Stocks Stocks
3 Bonds Bonds
4 Bonds USA Bonds
5 Bonds India Bonds
Maybe it is me who cannot translate other similar answers to a solution for me, but I have not been able to find the same question elsewhere.
/Jonas