Pandas >= 0.25 You can use explode
.
(大熊猫> = 0.25可以使用explode
。)
df = df.explode('bigrams')
Dummy Example:
(虚拟示例:)
import pandas as pd
df1 = pd.DataFrame({'score':[0.2,0.3],
'bigrams':[['a', 'b', 'c', 'e'],['f','g']]})
print(df1)
=========================
(========================)
df1:
(df1:)
score bigrams
0 0.2 [a, b, c, e]
1 0.3 [f, g]
===========================
(==========================)
df1 = df1.explode('bigrams')
print(df1)
=============================
(============================)
df1:
(df1:)
score bigrams
0 0.2 a
0 0.2 b
0 0.2 c
0 0.2 e
1 0.3 f
1 0.3 g
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…