我有一个数据框,其中的列包含某些行中的字符串和某些行中的列表。我怎么能将列表分解成单独的colummns。 这就是 -
>>> df2 = pd.DataFrame(["abc","[u'abc', u'xyz']"])
>>> df2
0
0 abc
1 [u'abc', u'xyz']
我想谈谈这个 -
0 1
0 abc None
1 abc xyz
我试过这样的事情,但是有问题 -
>>> for col, col_data in df2.iteritems():
... col_data = pd.get_dummies(pd.DataFrame(list(col_data)), prefix = col)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/remote/iims003/harpreet/anaconda2/lib/python2.7/site-packages/pandas/core/reshape.py", line 1095, in get_dummies
for (col, pre, sep) in zip(columns_to_encode, prefix, prefix_sep):
TypeError: izip argument #2 must support iteration