I have a DataFrame that has a column that I need to search using a wildcard. I tried this:
df = pd.read_excel('CHQ REG.xlsx',index=False)
df.sort_values(['CheckNumber'], inplace=True)
df[df.CheckNumber.str.match('888')]
df
This returns everything in by df
Here is my goal:
CheckBranch CheckNumber
Lebanon 8880121
Sample:
CheckBranch CheckNumber
Texas 4782436
Georgia 8967462
Lebanon 8880121
China 8947512
Try:
res = df[df['CheckNumber'].astype('string').str.match('888')]
print(res)
Output
CheckBranch CheckNumber
2 Lebanon 8880121
As an alternative:
res = df[df['CheckNumber'].astype('string').str.startswith('888')]
Yes it worked but what does the astype do? I assumed that the .str.match told python to look for a string?
astype converts the series to string type