'How to split() the members of a str column?
I have a dataframe with a column of strs all of the form '9xqv42x_general'. I need to extract (and have done a great many experiments trying) the geohash part from the string into a new column.
My attempts look something like:
df['geohasheything'].str.split('_')[0]
but these always seem to end with the error: "TypeError: 'float' object is not subscriptable"
How does a float even enter in to it? We're talking about a str.
Solution 1:[1]
Is it possible you have a null value in the dataframe? If those are all strings with one null value, similar to np.NaN, you will get a float error as np.NaN is a float.
If you drop those, the line you have should work.
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 | Kiril |
