python - 将数据帧字符串列分为两列 : one with multiple text words, 和一个数字量

标签 python python-3.x pandas dataframe

我有一列包含文本(多个单词),然后是一个数字(数字量)。它们由空格分隔。如何将它们分成两列?

1. Special Education Benefit 1,400.00
2. Accidental Death 123,000.00
3. Blanket Medical Indemnity - Accident 350
4. Blanket Medical Indemnity - Accident 250
5. Blanket Medical Indemnity - Accident 150
6. Accidental Death 65,000.00
7. Special Education Benefit 1,000.00

所需输出:

     Column1                                                  Column2
   
1.   Special Education Benefit                                1,400.00
2.   Accidental Death                                         123,000.00
3.   Blanket Medical Indemnity - Accident                     350
4.   Blanket Medical Indemnity - Accident                     250
5.   Blanket Medical Indemnity - Accident                     150
6.   Accidental Death                                         65,000.00
7.   Special Education Benefit                                1,000.00

所以: 不同栏目中的“特殊教育”和“1400.00”, “意外死亡”和“123,000.00”在不同的列

最佳答案

我们做rsplit

df.col.str.rsplit(' ', n=1,expand=True)

关于python - 将数据帧字符串列分为两列 : one with multiple text words, 和一个数字量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62347318/

相关文章:

python - pandas 0.8 重采样中的错误?

python - 如何使用 Python 的 CSV DictReader 解析 CSV 输出?

python - 组合两个数组而不重复

python - 断网后如何继续请求发帖

python-3.x - 如何将存储在 YYYYMMDD 中的日期转换为 pandas 中的日期时间格式

python - Pandas 数据框听写

Python:subprocess.popen:读取每一行输出

python - 多个处理器记录到同一个旋转文件

python - 如何将当前的 pygame 表面转换为更大的表面?

python - 删除 MultiIndex 中带有重复项的 NaN 行