简体   繁体   中英

How can I split a list of comma separated words in a Pandas column?

I was querying Stackoverflow to get some data ( https://data.stackexchange.com/stackoverflow/query/new ), and I have a data frame with Tags as a column. The tags originally were of the form

<html><css>

I managed to get them in the form of

html,css

I think an image of my Jupyter notebook can display it best: Jupyter笔记本行

How can I separate the tags so that they can become categorical variables, and I can transform them using something like get_dummies? Everything I've seen refers to actual lists, like [html,css], rather than just comma separated words.

为此,我们可以使用df['Tags'].str.get_dummies(',') ,该方法基本上执行split并将每个元素转换为自己的一键编码列。

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