从列中的列表中删除方括号
我的列有数据框中的列表。我只想删除方括号:
| Fruits |
| -------------------------------------|
| [apple, kiwi, pineapple, mango, lime]|
| [strawberry, cherry, kiwi, orange] |
| [...] |
所需的输出:
| Fruits |
| -----------------------------------|
| apple, kiwi, pineapple, mango, lime|
| strawberry, cherry, kiwi, orange |
| ... |
我已经尝试了这
for fruit in df['Fruits']:
df['Fruits'] = (','.join(word))
print(df['Fruits'])
不是我想要的输出,以及如何将新列表附加到新列(当然无需方括号)上,任何人都可以提供帮助?
I have column with lists in a dataframe. I want to just remove the square brackets:
| Fruits |
| -------------------------------------|
| [apple, kiwi, pineapple, mango, lime]|
| [strawberry, cherry, kiwi, orange] |
| [...] |
Desired Output:
| Fruits |
| -----------------------------------|
| apple, kiwi, pineapple, mango, lime|
| strawberry, cherry, kiwi, orange |
| ... |
I have tried this
for fruit in df['Fruits']:
df['Fruits'] = (','.join(word))
print(df['Fruits'])
The output is not what I want, and how can I append the new list to a new column (of course without the need of square brackets) anyone can help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iiuc,尝试以此为字符串存储或列表storge:
输出:
或,
输出:
注意:df_list和df_string字符串表示形式看起来相同。
IIUC, try this for string storage or list storge:
Output:
Or,
Output:
Note: df_list and df_string string representation looks identical.
您可以尝试使用
[]
字符字符字符,并用
repleent()
函数替换 carture function:You can try to replace the
[]
characters byempty
characters with thereplace()
function: