python - 从作为数据框一部分的列表的一部分中提取数字
问题描述
我通过在下面给出的列表中搜索列名中的关键字来从数据框中提取一列:
last_element = [total amount 2,200.00
Name: 1, dtype: object,
0
net amount 2,200.00
vat amount 0.00
total amount 2,200.00
Name: 1, dtype: object,
0
total amount 2,200.00
Name: 1, dtype: object,
0
net amount 2,200.00
vat amount 0.00
total amount 2,200.00
Name: 1, dtype: object,
0
total Total Amount (AED)
Name: 4, dtype: object]
我希望从中2,200
提取号码,但我无法做到这一点。
我尝试使用正则表达式提取它:
for i in l:
re = re.findall(r'\d+[,|.]?\d+?[,|.]?\d+?',i)
但是,它会引发错误
TypeError: expected string or bytes-like object
下面的代码显示了一个数据框列表,然后amount, balance and total
在列名中搜索关键字,然后在 中提取列的最后一个值last_element
。
for dataframe in lists_dataframe:
dataframe.columns= dataframe.columns.str.strip().str.lower()
keyword = ['total', 'amount', 'balance']
for key in keyword:
df = dataframe.filter(like = key)
if df.empty != True:
amount_column.append(df)
for s in amount_column:
last_element.append(s.iloc[-1])
for i in last_element:
res = re.findall(r'\d+[,|.]?\d+?[,|.]?\d+?',i)
print(res)
从 中last_element
,我希望提取像2,200.00
提前致谢!
解决方案
推荐阅读
- mysql - 如何通过命令 service mysql start 启动 mysql
- angular - 角度事件绑定我可以在 HTML 中创建自己的属性并将其发送到类文件吗
- laravel - Laravel artisan:每秒听一次命令
- java - 如何正确部署 Bean - JNDI、Weblogic 12C
- java - java桌面应用程序使用jdbc连接到数据库时出现问题
- c# - 与以前的值相比,如何放大或夸大变量值的微小变化?
- reactjs - React 上下文:如何传递函数?
- salesforce - 高级 Apex 专家 - 请确保已创建 Select One 标签
- python - 如何访问 Python 中 websocket 返回的数据?
- node.js - 将星体字符的 UTF16 转换为 UTF8