【发布时间】:2021-05-26 07:39:44
【问题描述】:
我有下一个带有字符串列(“信息”)的 DataFrame:
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."]})
我需要将“Info”中的数字提取到同一 df 中的新 4 列中。
第一行的值为 [78, 54, 9, 15]
我已经尝试过
df[["new1","new2","new3","new4"]]= df.Info.str.extract('(\d+(?:\.\d+)?)', expand=True).astype(int)
但我认为这更复杂。
问候,
【问题讨论】:
标签: python pandas string extract