पंडों के डेटाफ़्रेम से डुप्लिकेट मान निकालने के लिए, ड्रॉप_डुप्लिकेट () विधि का उपयोग करें। सबसे पहले, 3 कॉलम के साथ एक DataFrame बनाएं -
dataFrame = pd.DataFrame({'Car': ['BMW', 'Mercedes', 'Lamborghini', 'BMW', 'Mercedes', 'Porsche'],'Place': ['Delhi', 'Hyderabad', 'Chandigarh', 'Delhi', 'Hyderabad', 'Mumbai'],'UnitsSold': [95, 70, 80, 95, 70, 90]})
डुप्लिकेट मान हटाएं -
dataFrame = dataFrame.drop_duplicates()
उदाहरण
पूरा कोड निम्नलिखित है -
import pandas as pd # Create DataFrame dataFrame = pd.DataFrame({'Car': ['BMW', 'Mercedes', 'Lamborghini', 'BMW', 'Mercedes', 'Porsche'],'Place': ['Delhi', 'Hyderabad', 'Chandigarh', 'Delhi', 'Hyderabad', 'Mumbai'], 'UnitsSold': [95, 70, 80, 95, 70, 90]}) print"Dataframe...\n", dataFrame # counting frequency of column Car count = dataFrame['Car'].value_counts() print"\nCount in column Car" print(count) # removing duplicates dataFrame = dataFrame.drop_duplicates() print"\nUpdated DataFrame after removing duplicates...\n",dataFrame # counting frequency of column Car after removing duplicates count = dataFrame['Car'].value_counts() print"\nCount in column Car" print(count)
आउटपुट
यह निम्नलिखित आउटपुट उत्पन्न करेगा -
Dataframe... Car Place UnitsSold 0 BMW Delhi 95 1 Mercedes Hyderabad 70 2 Lamborghini Chandigarh 80 3 BMW Delhi 95 4 Mercedes Hyderabad 70 5 Porsche Mumbai 90 Count in column Car BMW 2 Mercedes 2 Porsche 1 Lamborghini 1 Name: Car, dtype: int64 Updated DataFrame after removing duplicates... Car Place UnitsSold 0 BMW Delhi 95 1 Mercedes Hyderabad 70 2 Lamborghini Chandigarh 80 5 Porsche Mumbai 90 Count in column Car BMW 1 Porsche 1 Lamborghini 1 Mercedes 1 Name: Car, dtype: int64