Page 76 - IPP-12-2024
P. 76

11   XII             99.0
            Class               object
            Pass_Percentage    float64
            dtype: object
            shape of the dataframe is::::
            (12, 2)

            Program 6: Write a program to filter out rows based on different criteria such as duplicate rows.
            Solution:
                import pandas as pd
                data = {
                    'Name': ['John', 'Alice', 'Bob', 'Alice', 'John'],
                    'Age': [25, 30, 35, 30, 25],
                    'City': ['New York', 'Los Angeles', 'Chicago', 'Los Angeles', 'New
                        York']
                }
                df = pd.DataFrame(data)
                print("Original DataFrame:")
                print(df)
                filtered_df = df.drop_duplicates()
                print("\nFiltered DataFrame (after removing duplicates):")
                print(filtered_df)
            Output:
            Original DataFrame:
                Name  Age         City
            0   John   25     New York
            1  Alice   30  Los Angeles
            2    Bob   35      Chicago
            3  Alice   30  Los Angeles
            4   John   25     New York

            Filtered DataFrame (after removing duplicates):
                Name  Age         City
            0   John   25     New York
            1  Alice   30  Los Angeles
            2    Bob   35      Chicago

            Program 7: Write a program to locate the 3 largest values in a data frame.
            Solution:
            import pandas as pd
            dic = {'Name': ['Rohit', 'Mohit', 'Deepak', 'Anil', 'Pankaj', 'Sohit',
            'Geeta'],
                   'MarksinIP': [85, 45, 92, 85, 98, 96, 84]}
            marks = pd.DataFrame(dic)
            sorted_marks = marks.sort_values(by='MarksinIP', ascending=False)
            top_3 = sorted_marks.head(3)
            print(top_3)
            Output:

                 Name  MarksinIP


            4  Pankaj         98
   71   72   73   74   75   76   77   78   79   80   81