python - pandas explode function only removes quotes
问题描述
I have a df that looks like this:
index | entry_terms
0 | ['Abate', 'Difos', 'Temephos']
1 | []
2 | ['a', 'b']
I'm trying to run the .explode
function the entry_terms column. Doing this straight on with df['entry_terms'].explode().to_frame()
doesn't make any changes whatsoever. So I do some troubleshooting.
df.dtypes
looks like this:
Unnamed: 0 int64
entry_terms object
dtype: object
and the class of the entry_terms
is <class 'str'>
. Someone recommends converting into a list prior to running the explode function, so I run the following: df['entry_terms'].apply(literal_eval)
followed by explode.to_frame
. Still no explosion/change. Any help would be greatly appreciated!
解决方案
要使用 df.explode() 函数,您只需要传递一个参数:具有类似列表的值的列的名称。
df3 = df.explode('entry_terms').drop_duplicates()
推荐阅读
- python - 使用 Python 在 Jenkins 上运行行为测试
- angular - 在功能模块中从同级路由导航到同级子路由时出错
- python - 将 5 级字典(以 pd.Series 作为值转换为 pandas DataFrame
- python - 如何创建一个 for 循环来检查列表元素与字典中包含的列表元素?
- mysql - 查找所有收入超过其公司所有员工平均工资的员工
- sparql - SPARQL wikidata 查询:获取相关维基百科文章可用的语言数量
- java - Spring Data JPA:一对一实例化问题:PersistentObjectException:分离实体传递给持久化
- deployment - 将我的应用程序部署到闪亮的服务器时出错
- java - 如何解决“价值
我尝试在标头中的应用程序中将令牌发送到服务器端。但是当我尝试发送令牌时出现此错误
org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject
我的服务器端是 laravel。
即使我尝试使用
utf-8
但- git - 强制 docker 缓存 git clone 命令