我有下一个带有字符串列(“Info”)的数据帧:
df = pd.DataFrame( {'Date': ["2014/02/02", "2014/02/03"], 'Info': ["Out of 78 shares traded during the session today, there were 54 increases, 9 without change and 15 decreases.", "Out of 76 shares traded during the session today, there were 60 increases, 4 without change and 12 decreases."]})
我需要提取的数字从“信息”到新的4列在同一个df
第一行的值为[78,54,9,15]
我一直在努力
df[["new1","new2","new3","new4"]]= df.Info.str.extract('(\d+(?:\.\d+)?)', expand=True).astype(int)
但我认为这更复杂
问候,
Extractall
可能更适合此任务我明白了,你在试图避免捕捉数字的小数部分,对吗?(第
(?:\.\d+)?
部分。)首先,如果需要所有匹配项,则需要使用^{}
extract
在第一次之后停止使用
df
,尝试以下代码:相关问题 更多 >
编程相关推荐