Creating New Column Based On Whether The Letter 'l' Or 'l' Is In The String Of Another Column
I am working with the Open Food Facts dataset which is very messy. There is a column called quantity in which in information about the quantity of respective food. the entries loo
Solution 1:
Use str.contains
with case=False
for boolean mask and convert it to integer
s by Series.astype
:
df['is_liquid']= df['liquids'].str.contains('L', case=False).astype(int)
print(df)
liquids is_liquid
0 365 g (314 ml) 1
1 992 g 0
2 2.46 kg 0
3 0,33 litre 1
4 15.87oz 0
5 250 ml 1
6 1 L 1
7 33 cl 1
Post a Comment for "Creating New Column Based On Whether The Letter 'l' Or 'l' Is In The String Of Another Column"