I attach my sample code below.
"""A simple pandas test"""
import pandas as pd
import numpy as np
from io import StringIO
df=pd.read_excel(r'cp.xlsx')
print('Raw data as read from Excel')
print(df)
print('')
df['Basepacksize'] = df['Basepacksize'].astype(str).astype(float)
print('After converting \'Basepacksize\' items to float types')
print(df)
print('')
bins= [0,10,15,30,50,100]
df1=pd.cut(df['Basepacksize'], bins=bins)
print('After using \'cut\' into separate bins')
print(df1)
print('')
spfuv = df['LDESC'].str.contains('SPF|UV')
print('After using "str.contains(\'SPF|UV\')"')
print(spfuv)
print('')
print('Iterating the items in the \'str.contains\' result')
for item in spfuv:
print(item)
My Excel files contains two columns, as shown in the raw data print. The content is based on guesses since you have refused to show us a sample of your data.
The output from the above code is:
Raw data as read from Excel
LDESC Basepacksize
0 SPF 10
1 UV 15
2 UV 21
3 SUN 23
4 SPF 27
5 UV 44
6 SUN 55
7 SUN 57
8 SPF 88
After converting 'Basepacksize' items to float types
LDESC Basepacksize
0 SPF 10.0
1 UV 15.0
2 UV 21.0
3 SUN 23.0
4 SPF 27.0
5 UV 44.0
6 SUN 55.0
7 SUN 57.0
8 SPF 88.0
After using 'cut' into separate bins
0 (0, 10]
1 (10, 15]
2 (15, 30]
3 (15, 30]
4 (15, 30]
5 (30, 50]
6 (50, 100]
7 (50, 100]
8 (50, 100]
Name: Basepacksize, dtype: category
Categories (5, interval[int64, right]): [(0, 10] < (10, 15] < (15, 30] < (30, 50] < (50, 100]]
After using "str.contains('SPF|UV')"
0 True
1 True
2 True
3 False
4 True
5 True
6 False
7 False
8 True
Name: LDESC, dtype: bool
Iterating the items in the 'str.contains' results
True
True
True
False
True
True
False
False
True
See
Working with text data — pandas 1.5.2 documentation[
^] for how to use the
contains
method on a series.
So you really need to study the pandas documentation for how to use these various methods and what results they produce, rather than guessing, and hoping that your guesses will yield valid results.