DataFrame 从字符串中提取 int/number 个值?
DataFrame Extract int/number values from string?
我有一个在一列中包含值的 df。
df
:
a
0 abc_test_0120_12346
1 def_abc def_0420_9658
我只想外带int/numbers。
例外输出是 df
:
a
0 012012346
1 04209658
想法是将非数字替换为空字符串:
df['a'] = df.a.str.replace('\D+', '')
print (df)
a
0 012012346
1 04209658
我有一个在一列中包含值的 df。
df
:
a
0 abc_test_0120_12346
1 def_abc def_0420_9658
我只想外带int/numbers。
例外输出是 df
:
a
0 012012346
1 04209658
想法是将非数字替换为空字符串:
df['a'] = df.a.str.replace('\D+', '')
print (df)
a
0 012012346
1 04209658