简体   繁体   English

Pandas 为 Excel 文件显示额外的未命名列

[英]Pandas display extra unnamed columns for an excel file

I'm working on a project using pandas library, in which I need to read an Excel file which has following columns:我正在使用 Pandas 库开发一个项目,在该项目中我需要读取一个包含以下列的 Excel 文件:

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

But when I read this file by using the Python code below:但是当我使用下面的 Python 代码读取这个文件时:

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

it returns some rows along with 6 unnamed columns with values as NAN .I don't know why these columns are displaying here?它返回一些行以及 6 个unnamed列,其值为NAN 。我不知道为什么这些列显示在这里?

Below is the link to a sample file as requested:以下是所要求的示例文件的链接:

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

Why are these extra columns appearing?为什么会出现这些额外的列?

As discussed in comments the problem seems to be that, there is extra data after last named columns.正如评论中所讨论的,问题似乎是,在last named列之后有额外的数据。 That's why you are getting Unnamed columns.这就是为什么你会得到Unnamed列。

If you wanna drop these columns this is how you can ignore these columns如果你想删除这些列,这是你可以忽略这些列的方法

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM