I have this dataframe :
Team Age
X [28,21,16,45]
B [18,19,16,23]
Y [32,27,34,23]
Run Code Online (Sandbox Code Playgroud)
And all I want is to get the brackets off the Age column to go further. I am doing the following:
df['Age']=[','.join(i) for i in df['Age']]
Run Code Online (Sandbox Code Playgroud)
但是这样做时我得到了can only join 一个可迭代的错误;如果我经过一个循环并打印结果,我就能得到想要的结果。
如果值是字符串:
df['Age'] = df['Age'].str.strip('[]')
Run Code Online (Sandbox Code Playgroud)
如果值是列表:
df['Age'] = df['Age'].str.join(',')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3863 次 |
| 最近记录: |