已关闭,此问题需要更focused。目前不接受答复。
**想改善这个问题吗?**更新问题,使其仅通过editing this post关注一个问题。
10天前关闭。
此帖子于10天前编辑并提交审核,未能重新打开帖子:
原始关闭原因未解决
Improve this question
从字符串列“code_input”的数据集开始,我将(通过Python)只为列“days”划分数字。我会将字符串的其余部分保存在“code_output”列中。
我的数据集示例:
| 代码输入|天数|码输出|
| - -----|- -----|- -----|
| ......这是什么?|......这是什么?|......这是什么?|
| 15.5C + 72HT| 3| 5.16C + 24HT|
| 46C + 28HT +6T| 2| 23C + 14HT + 3T|
| ......这是什么?|......这是什么?|......这是什么?|
谢谢你!
3条答案
按热度按时间zyfwsgd61#
假设你有一个pandas数据框:
你必须遍历每一行。您可以使用
re.sub
的callable asrepl
参数:输出:
lambda
函数将每个数字除以当前天数,并尝试简化数字:如果可能,向下转换为int
,否则返回舍入的float
。5lwkijsr2#
我完全不知道你最初的数据结构是什么样子的
但是对于字符串的解析和分割,你可以使用正则表达式从字符串中提取数字,然后用“天”来除它们
在那之后,你只需要“重新连接”你的字符串以得到最终的结果
示例:
打印
23C + 14HT + 3T
nbysray53#
您可以通过以下方式查找数字: