我有一个pandas数据帧:
figwheel
我想将其转换为字符串:ind
0 ['C']
1 ['C']
2 ['C']
3 ['C']
4 ['E']
5 ['E']
答案 0 :(得分:4)
您可以使用str
df['ind'].str[0].sum()
Out[197]: 'CCCCEE'
答案 1 :(得分:3)
from itertools import chain
df = pd.DataFrame({'ind': [['C'], ['C'], ['C'], ['C'], ['E'], ['E']]})
res = ''.join(chain.from_iterable(df['ind']))
print(res)
CCCCEE
答案 2 :(得分:0)
你可以这样做:
chain=""
for index, row in df.iterrows():
chain=chain+row['column']
return chain
如果您在迭代数据框时遇到问题,可以查看此How to iterate over rows in a DataFrame in Pandas?