- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 507 Articles for Pandas
181 Views
To return Index with duplicate values completely removed, use the index.drop_duplicates() method.At first, import the required libraries −import pandas as pdCreating the indexwith some duplicates −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane']) Display the index −print("Pandas Index with duplicates...", index)Return Index with duplicate values removed. The "keep" parameter with value "False" drops all occurrences for each set of duplicated entries −print("Index with duplicate values removed (drops all occurrences)...", index.drop_duplicates(keep = False))ExampleFollowing is the code −import pandas as pd # Creating the index with some duplicates index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane']) # Display the index print("Pandas Index ... Read More
219 Views
To return Index with duplicate values removed keeping the last occurrence, use the index.drop_duplicates() method. Use the keep parameter with value last.At first, import the required libraries −import pandas as pdCreating the index with some duplicates−index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane']) Display the index −print("Pandas Index with duplicates...", index)Return Index with duplicate values removed. The "keep" parameter with value "last" keeps the last occurrence for each set of duplicated entries −print("Index with duplicate values removed (keeping the last occurrence)...", index.drop_duplicates(keep='last')) ExampleFollowing is the code −import pandas as pd # Creating the index with some duplicates index = pd.Index(['Car', ... Read More
122 Views
To return Index with duplicate values removed except the first occurrence, use the index.drop_duplicates() method. Use the keep parameter with value first.At first, import the required libraries −import pandas as pdCreating the index with some duplicates −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane']) Display the index −print("Pandas Index with duplicates...", index)Return Index with duplicate values removed. The "keep" parameter with value "first" keeps the first occurrence for each set of duplicated entries −index.drop_duplicates(keep='first') ExampleFollowing is the code −import pandas as pd # Creating the index with some duplicates index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane']) # Display the ... Read More
285 Views
To make new Index with passed list of labels deleted, use the index.drop() method. Pass the list of labels in it.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane']) Display the index −print("Pandas Index...", index)A list containing labels to be dropped are passed −print("Updated index after deleting labels...", index.drop(['Bike', 'Ship'])) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane']) # Display the index print("Pandas Index...", index) # Return the dtype of the data print("The dtype object...", index.dtype) ... Read More
80 Views
To return the int position of the largest value in the Index, use the index.argmax() method.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) Display the index −print("Pandas Index...", index)Get the int position of the largest value in the Index −print("Get the int position of the largest value in the Index...", index.argmax()) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) # Display the index print("Pandas Index...", index) # ... Read More
84 Views
To return the int position of the smallest value in the Index, use the index.argmin() method.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) Display the index −print("Pandas Index...", index)Get the int position of the smallest value in the Index −print("Get the int position of the smallest value in the Index...", index.argmin()) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) # Display the index print("Pandas Index...", index) # ... Read More
223 Views
To return whether all elements in the index are True, use the index.any() method in Pandas.At first, import the required libraries −import pandas as pdCreating the index with some True (non-zero) and False (zero) elements −index = pd.Index([15, 25, 0, 0, 55]) Display the index −print("Pandas Index...", index)Return True if any element in the index is True: −print("Check whether any element in the index is True...", index.any()) ExampleFollowing is the code −import pandas as pd # Creating the index with some True (non-zero) and False (zero) elements index = pd.Index([15, 25, 0, 0, 55]) # Display the index ... Read More
85 Views
To return whether all elements in the index are True, use the index.all() method in Pandas.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index([15, 25, 35, 45, 55]) Display the index −print("Pandas Index...", index)Return True if all the elements in the index are True −print("Check whether all elements are True...", index.all()) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index([15, 25, 35, 45, 55]) # Display the index print("Pandas Index...", index) # Return a tuple of the shape of the underlying data print("A tuple of ... Read More
133 Views
To return the memory usage of the Index values, use the index.memory_usage() method in Pandas.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index([15, 25, 35, 45, 55]) Display the index −print("Pandas Index...", index)Get the memory usage of the values −print("The memory usage...", index.memory_usage()) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index([15, 25, 35, 45, 55]) # Display the index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the index...", index.size) # Return a tuple of ... Read More
2K+ Views
To check if the index is empty with 0 elements, use the index.empty property in Pandas.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index([]) Display the index −print("Pandas Index...", index)Check for empty index −print("Is the index empty?", index.empty) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index([]) # Display the index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the index...", index.size) # check for empty index print("Is the index empty?", index.empty)OutputThis will produce the following code ... Read More