我有一个名为BREADS
的列,有5行,我想将该列和值拆分为4列,即B
、REA
、D
和S
BREADS
>2319-22-<21
>1513-16-<19
>1319-25-<22
>1617-21-<25
>1011-15-<17
预期结果
B, REA , D, S ### column names
>23 , 19-22 , - , <21
>15 , 13-16 , - , <19
>13 , 19-25 , - , <22
>16 , 17-21 , - , <25
>10 , 11-15 , - , <17
# Key: > greater than and < less than, - hyphen in the column 'D'
我的尝试
###### in python
# for column 'B'
df['B'] = df['BREADS'].astype(str).str[0:4] # returns '>23','>15',.....,'>10'
#### in R
library(stringr)
str_split_fixed(df$BREADS, "", 2)
您可以使用pandas str.extract将数据拉入单独的列中;这里的假设是每一行的数据是一致的:
在
R
中带有extract
fromtidyr
的选项-输出
数据
对于Python:
相关问题 更多 >
编程相关推荐