简体   繁体   English

Dataframe中包含字符、符号和数字的复杂计量单位如何从计量值中分离出来?

[英]How do I separate complicated measurement unit containing both characters, symbols and number from measurement value in Dataframe?

I am able to separate measurement units which are not complicated from measurement value if they appear together in DataFrame by using suggested answer provided in How do I separate measurement value and unit into their respective columns if they appear together in DataFrame?如果它们一起出现在 DataFrame 中,我可以将不复杂的测量单位与测量值分开,方法是使用如果测量值和单位一起出现在 DataFrame 中,我如何将它们分开到各自的列中?

However, I couldn't separate complicated measurement unit like area from measurement value as shown in below DataFrame.但是,我无法将面积等复杂的测量单位与测量值分开,如下图 DataFrame 所示。

measurments测量值 value价值 unit单元
mea1 mea1 12.8875cm2 12.8875cm2
mea2测量值2 33.1 mL/min/1.73m2 33.1 毫升/分钟/1.73 平方米
mea3 mea3 2.53mg / dL 2.53毫克/分升
mea4 mea4 0.005ml/ min / m2 0.005毫升/分钟/平方米
mea5测量值5 0.8ml/m2 0.8毫升/平方米
mea6 mea6 0.73x10^3/UL 0.73x10^3/UL

May I know how could I separate complicated measurement unit from measurement value in Dataframe?请问Dataframe中如何将复杂的计量单位与计量值分开? The expected output is shown below:预期的output如下图:

measurments测量值 value价值 unit单元
mea1 mea1 12.8875 12.8875 cm2平方厘米
mea2测量值2 33.1 33.1 mL/min/1.73m2毫升/分钟/1.73平方米
mea3 mea3 2.53 2.53 mg/dL毫克/分升
mea4 mea4 0.005 0.005 ml/min/m2毫升/分钟/平方米
mea5测量值5 0.8 0.8 ml/m2毫升/平方米
mea6 mea6 0.73 0.73 x10^3/UL x10^3/UL

Thanks.谢谢。

Use str.extract :使用str.extract

df[['value', 'unit']] = df['value'].str.extract(r'(\d+.?\d*)\s*(.*)')

output: output:

  measurments    value           unit
0        mea1  12.8875            cm2
1        mea2     33.1  mL/min/1.73m2
2        mea3     2.53        mg / dL
3        mea4    0.005   ml/ min / m2
4        mea5      0.8          ml/m2
5        mea6     0.73       x10^3/UL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DataFrame中同时出现的测量值和单位如何分列到各自的列中? - How do I separate measurement value and unit into their respective columns if they appear together in DataFrame? 如何将 dataframe 中的混合测量值转换为统一测量值 - How to convert a mixed measurement values in dataframe to a uniform measurement Python Turtle的计量单位 - Python Turtle unit of measurement 如何按组进行高斯拟合和 FWHM 测量? - How to do Gaussian fit and FWHM measurement by group? 如何在influxdb测量中插入/存储字符串值? - How to insert/store a string value in influxdb measurement? opencv中亮度和对比度的单位测量 - Unit measurement for brightness and contrast in opencv geopandas中的GIS距离测量单位 - GIS distance measurement unit in geopandas 如何在Python中将度量及其误差估计四舍五入为指定数量的有效数字? - How would I round a measurement and its error estimate to a specified number of significant figures in Python? 我如何通过将 append dataframe 传递给 function 并返回包含两者的 dataframe 来将其传递给另一个 dataframe? - How do I append a dataframe to another dataframe by passing it to a function, and returning a dataframe containing both? 使用正则表达式从字符串中提取测量尺寸和数字 - Extract measurement dimensions and number from string using regex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM