Reputation: 1093
From a column (company_name) in a data frame df1, I want to get all the values which starts with a number. I am writing the code as -
df2 = df1[df1.company_name.str[0].isdigit()].copy()
I receive the following error -
AttributeError: 'Series' object has no attribute 'is digit'
Upvotes: 1
Views: 402
Reputation: 862591
You need add str
, because str.isdigit
. Also I think copy()
is not necessary:
df2 = df1[df1.company_name.str[0].str.isdigit()]
Sample:
import pandas as pd
df1 = pd.DataFrame({'company_name': ['aa','1ss','wer']})
print (df1)
company_name
0 aa
1 1ss
2 wer
df2 = df1[df1.company_name.str[0].str.isdigit()]
print (df2)
company_name
1 1ss
Upvotes: 1