我有一个看起来像这样的 df:
index | entry_terms
0 | ['Abate', 'Difos', 'Temephos']
1 | []
2 | ['a', 'b']
我正在尝试在 entry_terms 列中运行 .explode
函数。直接使用 df['entry_terms'].explode().to_frame()
执行此操作不会进行任何更改。所以我做了一些故障排除。
df.dtypes
看起来像这样:
Unnamed: 0 int64
entry_terms object
dtype: object
entry_terms
的类是 <class 'str'>
。有人建议在运行爆炸函数之前转换为列表,因此我运行以下命令:df['entry_terms'].apply(literal_eval)
后跟 explode.to_frame
。仍然没有爆炸/变化。任何帮助将不胜感激!
答案 0 :(得分:0)
要使用 df.explode() 函数,您只需传递一个参数:具有类似列表值的列的名称。
df3 = df.explode('entry_terms').drop_duplicates()