1

I have a Pandas DataFrame that looks like so:

<class 'pandas.core.frame.DataFrame'>
Int64Index: 1072 entries, 0 to 1071
Data columns (total 10 columns):
city            1072  non-null values
latitude        1072  non-null values
longitude       1072  non-null values
manufacturer    1072  non-null values
name            1072  non-null values
offering        1072  non-null values
platformID      1072  non-null values
procedure       1072  non-null values
properties      1072  non-null values
sensorID        1072  non-null values
dtypes: object(10)

properties is a list of string values:

df_devices.head(1).properties
Out[79]: 0    [urn:average_wind, urn:dew_point]

I'd like to select records that only contain the 'urn:dew_point' entry, but I'm not sure how to filter them (using isin, or an alternative)

1 Answer 1

3

You can simply use an apply to do this:

In [11]: df = pd.DataFrame([[['urn:dew_point'], 1]], columns=['properties', 'id'])

In [12]: df
Out[12]:
        properties  id
0  [urn:dew_point]   1

In [13]: df[df['properties'].apply(lambda x: 'urn:dew_point' in x)]
Out[13]:
        properties  id
0  [urn:dew_point]   1

If this were simply part of a string column you could use str.contains:

In [21]: df = pd.DataFrame([['urn:dew_point', 1]], columns=['properties', 'id'])

In [22]: df['properties'].str.contains('urn:dew_point')
Out[22]:
0    True
Name: properties, dtype: bool

In [23]: df[df['properties'].str.contains('urn:dew_point')]
Out[23]:
      properties  id
0  urn:dew_point   1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.