简体   繁体   English

如何在Pandas列中拆分逗号分隔的单词列表?

[英]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. 我正在查询Stackoverflow以获取一些数据( https://data.stackexchange.com/stackoverflow/query/new ),并且我有一个带有标签作为列的数据框。 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笔记本的图像可以最好地显示它: Jupyter笔记本行

How can I separate the tags so that they can become categorical variables, and I can transform them using something like get_dummies? 如何分隔标签,以便它们可以成为分类变量,并可以使用类似get_dummies的方法来对其进行转换? Everything I've seen refers to actual lists, like [html,css], rather than just comma separated words. 我所看到的所有内容都是指实际列表,例如[html,css],而不仅仅是逗号分隔的单词。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将用逗号分隔的单词(txt 文件)重新排列为 pandas 中的单词列表? - How do I rearrange words separated with comma (txt file) to list of words in pandas? 如何在Python中高效地拆分用引号引起来的逗号分隔单词? - How can I split comma separated words wrapped in quotes efficiently in Python? 包含对象列表的pandas列,根据键名拆分此列,并将值存储为逗号分隔的值 - pandas column containing list of objects, split this column based upon keynames and store values as comma separated values 以逗号分隔值的大熊猫分隔列,但保持顺序 - Split column in pandas of comma separated values but maintining the order 根据 pandas 中的特定条件拆分以逗号分隔的列 - Split a column which is separated by comma based on certain condition in pandas 列存储为列表; 如何在 pandas python 中拆分为 COLUMNS? - Column stored as List; how can I split as COLUMNS in pandas python? 如何解析此逗号分隔值列表 - How can I parse this list of comma separated values 如何将逗号分隔的字典字符串拆分为Pandas数据框 - How to Split a comma separated string of dictionaries into a Pandas dataframe 熊猫:将每列汇总到一个用逗号分隔的列表中,没有重复项 - Pandas: Aggregate each column into a comma separated list without duplicates 将以逗号分隔的单词读入熊猫 - Reading comma-separated words into pandas
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM