Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I search for a value that starting with a specific number in a column of a dataframe?

I have a DataFrame like this

example = {'x': [121,'201-208-209','300A',320,'100A'], 'y': ['a','b','c','d','e']}
df = pd.DataFrame(example)

I want to know wich values are starting with a specific number. I want to know this because this way I can better categorize my database. For example, if i know that there is a row that the value of the columns "x" start with 1 I will agregate a column with "Floor 1" in the same row, but if this value start with 2 it will be "Floor 2" and so on.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Would ‘startswith’ work ?

df['x'].str.startswith('1')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading