I have some DataFrame:
d = {'fruit': ['apple', 'pear', 'peach'], 'values': ['apple_1_0,peach_1_5','pear_1_3','mango_1_0,banana_1_0,pineapple_1_10']}
df = pd.DataFrame(data=d)
df
fruit values
0 apple apple_1_0,peach_1_5
1 pear pear_1_3
2 peach mango_1_0,banana_1_0,pineapple_1_10
The strings in the values column are comma separated, and I'd like the strings that contain the substring '_1_0'.
Desired output:
fruit values
0 apple apple_1_0
1 pear NaN
2 peach mango_1_0,banana_1_0
Something like this is somewhat close to what I'm trying to do but is painfully slow over ~100,000 rows:
for row in range(len(df)):
print([zero for zero in df['values'].str.split(',', expand=False)[row] if "_1_0" in zero])
['apple_1_0']
[]
['mango_1_0', 'banana_1_0']