Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从字符串中提取带$以上十进制运算符的数字_Python_Regex_Pandas - Fatal编程技术网

Python 从字符串中提取带$以上十进制运算符的数字

Python 从字符串中提取带$以上十进制运算符的数字,python,regex,pandas,Python,Regex,Pandas,还有好几个,我还是不能解决我的问题 我有一个扑克游戏中的pandas列,想从中分析锅的大小,因此我需要在$之后提取数字(使用.decimalseparator)。该列如下所示: Action Player (8, 5) won the $5.40 main pot with a Straight ... Player (A, 2) won the $21.00 main pot with a flush ... 运行时:df['number']=df['action'].str.extract

还有好几个,我还是不能解决我的问题

我有一个扑克游戏中的pandas列,想从中分析锅的大小,因此我需要在
$
之后提取数字(使用.decimalseparator)。该列如下所示:

Action
Player (8, 5) won the $5.40 main pot with a Straight
...
Player (A, 2) won the $21.00 main pot with a flush
...
运行时:
df['number']=df['action'].str.extract('([0-9][,.]*[0-9]*))
它没有给我预期的结果结果应该是:

number
5.40
...
21.00
你可以用

>>将熊猫作为pd导入
>>>df=pd.DataFrame({'action':['Player(8,5)以平手赢得$5.40的主锅,'Player(a,2)以平手赢得$21.00的主锅]})
>>>df['action'].str.extract(r'\$(\d+(?:[,.]\d+*)),expand=False)
0     5.40
1    21.00
名称:操作,数据类型:对象
\$(\d+(?:[,.]\d+*)
模式匹配一个文字符号
$
符号,然后将任何一个或多个数字、零个或多个
序列以及一个或多个数字捕获到组1中

看到了吗。

像这样?