There is a list of values
weather = ['cloudy', 'sunny']
I've got a dataframe with an old column "weather". We switched to 2 newer columns with boolean values, so all the old columns need to be accounted for.
Here is my dataframe now:
[In]
data = [['cloudy', False, False], ['sunny', False, False]]
df = pd.DataFrame(data, columns=['old', 'cloudbool', 'sunbool'])
df
[Out]
old cloudbool sunbool
0 cloudy False False
1 sunny False False
Desired output:
[In]
data = [['cloudy', True, False], ['sunny', False, True]]
df = pd.DataFrame(data, columns=['old', 'cloudbool', 'sunbool'])
[Out]
old cloudbool sunbool
0 cloudy True False
1 sunny False True
I know I could do something like what I've got below, but I've got a list of "weather types" much longer than 2.
df.loc[df['old'] == 'cloudy', ['cloudbool']] = True
I hope I conveyed that properly. Thank you