简体   繁体   中英

Splitting at specific string from a dataframe column in Python

I have a dataframe with a column called "Spl" with the values below: I am trying to extract the values next to 'name': strings (some rows have multiple values) but I see the new column generated with the specific location of the memory. I used the below code to extract. Any help how to extract the values after "name:" string is much appreciated.

Column values:

'name': 'Chirotherapie', 'name': 'Innen Medizin'
'name': 'Manuelle Medizin'
'name': 'Akupunktur', 'name': 'Chirotherapie', 'name': 'Innen Medizin'

Code:

df['Spl'] = lambda x: len(x['Spl'].str.split("'name':"))

Output:

<function <lambda> at 0x0000027BF8F68940>

Just simply do:-

df['Spl']=df['Spl'].str.split("'name':").str.len()

Just do count

df['Spl'] = df['Spl'].str.count("'name':")+1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM