'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 which 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 aggregate a column with "Floor 1" in the same row, but if this value start with 2 it will be "Floor 2" and so on.
Solution 1:[1]
Would 'startswith' work ?
df['x'].str.startswith('1')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Weigel |
