Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with python duplicate values

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to deal with python duplicate values". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to deal with python duplicate values" can help you solve your doubts.

Today, to deal with duplicate values, first create a DataFrame that contains duplicate values, as follows:

Import pandas as pddata = pd.DataFrame ([[1Jing 2], [1JI 2], [3jue 4]], columns = ['axie dagger']) print (data)

We print it out, and the results are as follows:

We can see that the first and second lines are duplicated, and the amount of data here is relatively small, which can be directly observed with the naked eye, but if there is a large amount of data, we need to use the diplicated () function to query, and we use it to check the duplicate values of the data above.

Data [data.duplicated ()]

We can see that it prints out a line with an index of 1. What if there are three lines that are the same? Let's try it next!

Import pandas as pddata = pd.DataFrame ([[1djue 2], [1d2], [1d2], [3pr 4]], columns = ['axiajiaozhongb']) data [data.duplicated ()]

The results are as follows:

As you can see, the duplicates will be displayed except for the data that appears first.

If we want to count how many lines are duplicated, we can use the sum () function as follows:

Data.duplicated () .sum ()

In many cases, we need to delete the duplicate data, and then we can use the drop_duplicated () function. Let's delete the duplicate line of data.

Data.drop_duplicated ()

An error occurred when the code was just executed, and it turned out to be duplicates, not duplicated!

Note, however, that deleting duplicates with drop_duplicates () does not affect the structure of the data, and if you want to change the data structure, you have to re-assign the value. If you want to delete the duplicate value of a column, simply add the column name in parentheses.

As follows:

After reading this, the article "how to deal with python duplicate values" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report