gpt4 book ai didi

python - Pandas 显示 excel 文件的额外未命名列

转载 作者:太空宇宙 更新时间:2023-11-04 02:29:08 24 4
gpt4 key购买 nike

我正在使用 pandas 库开发一个项目,其中我需要读取一个包含以下列的 Excel 文件:

'invoiceid', 'locationid', 'timestamp', 'customerid', 'discount', 'tax',
'total', 'subtotal', 'productid', 'quantity', 'productprice',
'productdiscount', 'invoice_products_id', 'producttax',
'invoice_payments_id', 'paymentmethod', 'paymentdetails', 'amount'

但是当我使用下面的 Python 代码读取这个文件时:

df_full = pd.read_excel('input/invoiced_products_noinvoiceids_inproduct_v2.0.xlsx', sheet_name=0,)
df_full.head()

它返回一些行以及 6 个未命名 列,值为 NAN。我不知道为什么这些列显示在这里?

下面是请求的示例文件的链接:

https://mega.nz/#!0MlXCBYJ!Oim9RF56h6hUitTwqSG1354dIKLZEgIszzPrVpfHas8

为什么会出现这些额外的列?

最佳答案

正如评论中所讨论的,问题似乎在于,last named 列之后有额外的数据。这就是您获得 Unnamed 列的原因。

如果你想删除这些列,这就是你可以忽略这些列的方法

df_full = df_full[df_full.filter(regex='^(?!Unnamed)').columns]

关于python - Pandas 显示 excel 文件的额外未命名列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com