4

I have a Dataframe of two columns, with strings in one column and lists in the other, as below:

      RSD_TYPE                                FILTER LIST
   0     AQ500          [N/A, Z mean, SNR mean, Dir mean]
   1    Triton  [wipe mean, Z mean, Avail mean, Dir mean]
   2  Windcube            [N/A, W mean, Q mean, Dir mean]
   3    Zephir     [Rain mean, W mean, Packets, dir mean]

I want to return a list based on partial string match with the elements of the column RSD_TYPE. E.G. search for which row has a partial string match with "AQ5", then return the corresponding list item from that row, in this case [N/A, Z mean, SNR mean, Dir mean].

The plan was to do this using .get_value, but first I need to have a way of returning (row) index using a partial string match. That's where I'm stuck. I know how to run a partial string match on column titles but I can't find a way to run it on the elements in that column (or the dataframe as a whole). Any ideas?

Many thanks in advance.

1
  • Also recommend taking a look at this answer. Commented Apr 7, 2019 at 21:03

1 Answer 1

7

Try this:

df[df['RSD_TYPE'].str.contains("AQ5")]['FILTER LIST']

Example:

In [3]: df
Out[3]:
   RSD_TYPE                                FILTER LIST
0     AQ500          [N/A, Z mean, SNR mean, Dir mean]
1    Triton  [wipe mean, Z mean, Avail mean, Dir mean]
2  Windcube            [N/A, W mean, Q mean, Dir mean]
3    Zephir     [Rain mean, W mean, Packets, dir mean]

[4 rows x 2 columns]

In [4]: df[df['RSD_TYPE'].str.contains("AQ5")]
Out[4]:
  RSD_TYPE                        FILTER LIST
0    AQ500  [N/A, Z mean, SNR mean, Dir mean]

[1 rows x 2 columns]

In [5]: df[df['RSD_TYPE'].str.contains("AQ5")]['FILTER LIST']
Out[5]:
0    [N/A, Z mean, SNR mean, Dir mean]
Name: FILTER LIST, dtype: object
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.