我想创建一个如下所示的熊猫数据框。
id words
1 [a, b, c, d, e, f, g]
1 [h, I, o]
1
1 [a, b, c]
2 [e, f, g, m, n, q, r, s]
2 [w, j, f]
3 [l, t, m, n, q, s, a]
3 [c, d, e, f, g]
4
4 [f, g, z]
我尝试了以下代码:
import pandas as pd
d = {'id': [1, 1, 1, 1, 2, 2, 3, 3, 4, 4], 'words': [[a, b, c, d, e, f, g], [h, I, o], '', [a, b, c], [e, f, g, m, n, q, r, s], [w, j, f], [l, t, m, n, q, s, a], [c, d, e, f, g], '', [f, g, z]]}
df = pd.DataFrame(data=d)
我收到以下错误:
NameError: name 'a' is not defined