I have dataframe column which is array of strings
JavaScript
x
9
1
````
2
| fruits |
3
|--------------------------------|
4
|['fruit=apple', 'fruit=banana'] |
5
|['fruit=orange', 'fruit=banana']|
6
|['fruit=apple', 'fruit=orange'] |
7
|['fruit=orange', 'fruit=orange']|
8
````
9
I want to get result like
JavaScript
1
9
1
``
2
| fruits |
3
|--------------------|
4
|['apple', 'banana'] |
5
|['orange', 'banana']|
6
|['apple', 'orange'] |
7
|['orange', 'orange']|
8
``
9
I want to remove substring
'fruit='
Advertisement
Answer
You can apply a function to the column. In this case split each string by =
and take the last element of the result.
JavaScript
1
2
1
df['fruits'].apply(lambda x: [f.split('=')[-1] for f in x])
2