【发布时间】:2021-08-30 13:40:15
【问题描述】:
我有一个带有列的数据框
id bins
1 (2, 3]
2 (4, 5]
3 (6, 7]
4 (8, 9]
5 (10, 11]
我正在尝试得到这样的东西。
id bins
1 2 - 3
2 4 - 5
3 6 - 7
4 8 - 9
5 10 - 11
我的目标是使用正则表达式来实现这一点。恐怕我不是正则表达式方面的专家。这部分是我尝试但没有成功的解决方案。
df['bins'].astype(str).str.replace(']', ' ')
df['bins'].astype(str).str.replace(',', ' - ')
df['bins'] = df['bins'].apply(lambda x: x.replace('[','').replace(']',''))
任何帮助将不胜感激!
提前致谢
【问题讨论】:
标签: python regex data-wrangling