[英]Split 7 digit into separate columns in csv with python
Hi I have 100 data in csv file I want to split 7 digit number into seprate columns with python My csv file is like this:嗨,我在 csv 文件中有 100 个数据,我想将 7 位数字拆分为 python 的单独列我的 csv 文件是这样的:
A一种 |
---|
1234567 1234567 |
Split into new columns:拆分为新列:
B乙 | C C | D丁 | E乙 | F F | G G | H H |
---|---|---|---|---|---|---|
1 1个 | 2 2个 | 3 3个 | 4 4个 | 5 5个 | 6 6个 | 7 7 |
I try我试试
Splitdigit= df['A']>str.split(expand=true).add_perfix('A')
If you have strings, you can use:如果你有字符串,你可以使用:
out = df['A'].astype(str).str.split('(?<=.)(?=.)', expand=True)
Output: Output:
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
With the column names:使用列名称:
from string import ascii_uppercase
out = (df['A'].astype(str).str.split('(?<=.)(?=.)', expand=True)
.rename(columns=dict(enumerate(ascii_uppercase[1:])))
)
Output: Output:
B C D E F G H
0 1 2 3 4 5 6 7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.