I have a data frame sample below and trying to get to the following output. Have looked through a lot of examples but none seem to handle this specific scenario. See the sample data.
Not sure if there is a way to achieve this using apply or map but I am not tied to it.
df = pd.DataFrame({'collen': [5, 3, 2, None, 3], 'colstr': ['turquoise', 'white', 'blue', 'red',None]})
collen colstr
0 5.0 turquoise
1 3.0 white
2 2.0 blue
3 NaN red
4 3.0 None
Expected outcome:
collen colstr new_col_str
0 5.0 turquoise turqu
1 3.0 white whi
2 2.0 blue bl
3 NaN red red
4 3.0 None None