久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

drop_duplicates 在 pandas 中不起作用?

drop_duplicates not working in pandas?(drop_duplicates 在 pandas 中不起作用?)
本文介紹了drop_duplicates 在 pandas 中不起作用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的代碼的目的是導入 2 個 Excel 文件,比較它們,然后將差異打印到一個新的 Excel 文件中.

The purpose of my code is to import 2 Excel files, compare them, and print out the differences to a new Excel file.

但是,在連接所有數據并使用 drop_duplicates 函數后,代碼會被控制臺接受.但是,當打印到新的 excel 文件時,當天仍會保留重復項.

However, after concatenating all the data, and using the drop_duplicates function, the code is accepted by the console. But, when printed to the new excel file, duplicates still remain within the day.

我錯過了什么嗎?drop_duplicates 函數是否無效?

Am I missing something? Is something nullifying the drop_duplicates function?

我的代碼如下:

import datetime
import xlrd
import pandas as pd
#identify excel file paths
filepath = r"excel filepath"
filepath2 = r"excel filepath2"
#read relevant columns from the excel files
df1 = pd.read_excel(filepath, sheetname="Sheet1", parse_cols= "B, D, G, O")
df2 = pd.read_excel(filepath2, sheetname="Sheet1", parse_cols= "B, D, F, J")
#merge the columns from both excel files into one column each respectively
df4 = df1["Exchange Code"] + df1["Product Type"] + df1["Product Description"] + df1["Quantity"].apply(str)
df5 = df2["Exchange"] + df2["Product Type"] + df2["Product Description"] + df2["Quantity"].apply(str)
#concatenate both columns from each excel file, to make one big column containing all the data
df = pd.concat([df4, df5])
#remove all whitespace from each row of the column of data
df=df.str.strip()
df=["".join(x.split()) for x in df] 
#convert the data to a dataframe from a series
df = pd.DataFrame({'Value': df}) 
#remove any duplicates
df.drop_duplicates(subset=None, keep="first", inplace=False)
#print to the console just as a visual aid
print(df)
#print the erroneous entries to an excel file
df.to_excel("Comparison19.xls") 

推薦答案

你有 inplace=False 所以你沒有修改 df.你想要一個

You've got inplace=False so you're not modifying df. You want either

 df.drop_duplicates(subset=None, keep="first", inplace=True)

 df = df.drop_duplicates(subset=None, keep="first", inplace=False)

這篇關于drop_duplicates 在 pandas 中不起作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产日韩精品一区 | 欧美黄色网 | 国产小视频在线观看 | 天天久| 日韩精品一二三 | 欧美日韩国产一区二区 | 欧美日韩在线一区二区三区 | 国产欧美精品一区二区三区 | 国产片淫级awww | 亚洲精品一区二区三区蜜桃久 | 国产一区二区三区网站 | 欧美二区在线 | 成人一区二区三区在线观看 | 日韩在线欧美 | 五月综合激情在线 | 亚洲精品日韩在线 | www.青青草| 国产成人久久av免费高清密臂 | 亚洲欧美日韩电影 | 成人三区四区 | 成人网在线看 | 国产精品久久久久久久久久久免费看 | 国产日韩欧美综合 | 国产成人一区二区三区久久久 | 欧美精品成人 | 亚洲精品国产成人 | 日韩美女在线看免费观看 | 精品视频久久久 | 精品一区二区三区四区五区 | 欧美性影院 | 亚洲成人精品视频 | 成人免费视频网站在线观看 | 日韩不卡视频在线 | 亚洲综合区 | 亚洲欧美日韩久久久 | 一区在线免费视频 | 亚洲444kkkk在线观看最新 | 精品一二三 | 日韩视频一区二区三区 | 亚洲在线 | 国产69精品久久99不卡免费版 |