简体   繁体   中英

Python Pandas giving wrong number of columns on df.loc

在此处输入图像描述

So I tried printing my quantity column after data cleanup, and its bugged, it showed 202634 rows even if it is 202129 rows long. I tried saving the data into excel and checking manually, the real number of rows is 202129, so why does pandas show 202634? The data before cleaning was 203000+ rows. Anyone knows why is this? How can this be fixed?

This is because some of the samples have been deleted, but the index number of the next sample has not been replaced. For this, it is enough to reset the index numbers as follows:

df = df.reset_index(drop = True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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