
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 26504 Articles for Server Side Programming

2K+ Views
To return a list of the Index values, use the index.to_list() method in Pandas. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index([50.4, 10.2, 70.5, 110.5, 90.8, 50.6]) Display the Pandas index −print("Pandas Index...", index)Return a list −print("List of the index values...", index.to_list()) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index([50.4, 10.2, 70.5, 110.5, 90.8, 50.6]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the index...", index.size) # Return the ... Read More

312 Views
To create an Index with values cast to dtypes, use the index.astype() method in Pandas. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index([50.4, 10.2, 70.5, 110.5, 90.8, 50.6]) Display the Pandas index −print("Pandas Index...", index)Convert datatype to int64 −index.astype('int64') ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index([50.4, 10.2, 70.5, 110.5, 90.8, 50.6]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the index...", index.size) # Return the dtype of the ... Read More

159 Views
To show which entries in a Pandas Index are not NA, use the index.notna() method. At first, import the required libraries -import pandas as pd import numpy as npCreating Pandas index with some NaN values −index = pd.Index([5, 65, np.nan, 17, 75, np.nan]) Display the Pandas index −print("Pandas Index...", index)Show which entries in a Pandas index are not-NA. Return True for non-NA entries −print("Check which entries are not-NA...", index.notna()) ExampleFollowing is the code −import pandas as pd import numpy as np # Creating Pandas index with some NaN values index = pd.Index([5, 65, np.nan, 17, 75, np.nan]) # ... Read More

122 Views
To show which entries in a Pandas Index are NA, use the index.isna() in Pandas. At first, import the required libraries -import pandas as pd import numpy as npCreating Pandas index with some NaN values −index = pd.Index([5, 65, np.nan, 17, 75, np.nan]) Display the Pandas index −print("Pandas Index...", index)Show which entries in a Pandas index are NA. Return True for NA entries −print("Check which entries are NA...", index.isna()) ExampleFollowing is the code −import pandas as pd import numpy as np # Creating Pandas index with some NaN values index = pd.Index([5, 65, np.nan, 17, 75, np.nan]) # ... Read More

947 Views
To drop the value when all levels are NaN in a Multi-index, use the multiIndex.dropna() method. Set the parameter how with value all.At first, import the required libraries -import pandas as pd import numpy as npCreate a multi-index with all NaN values. The names parameter sets the names for the levels in the index −multiIndex = pd.MultiIndex.from_arrays([[np.nan, np.nan], [np.nan, np.nan]], names=['a', 'b'])Drop the value when all levels iareNaN in a Multi-index. With all NaN values, the dropna() will drop all the values, if the "how" parameter of the dropna() is set "all" −print("Dropping the values when all levels are NaN...", ... Read More

795 Views
To drop the value when any level is NaN in a Multi-index, use the multiIndex.dropna() method. Set the parameter how with value any.At first, import the required libraries -import pandas as pd import numpy as npCreate a multi-index with some NaN values. The names parameter sets the names for the levels in the index −multiIndex = pd.MultiIndex.from_arrays([[5, 10], [np.nan, 20], [25, np.nan], [35, 40]], names=['a', 'b', 'c', 'd'])Drop the value when any level is NaN in a Multi-index. Even with a single NaN value, the dropna() will drop all the values. The "how" parameter of the dropna() is used with ... Read More

414 Views
To return Index without NaN values, use the index.dropna() method in Pandas. At first, import the required libraries −import pandas as pd import numpy as npCreating Pandas index with some NaN values as well −index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30]) Display the Pandas index −print("Pandas Index...", index)Drop only the NaN values −print("The Index object after removing NaN values...", index.dropna())ExampleFollowing is the code −import pandas as pd import numpy as np # Creating Pandas index with some NaN values as well index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30]) # Display ... Read More

638 Views
To fill NaN values with the specified value in an Index object, use the index.fillna() method in Pandas. At first, import the required libraries −import pandas as pd import numpy as npCreating Pandas index with some NaN values as well −index = pd.Index([50, 10, 70, np.nan, 90, 50, np.nan, np.nan, 30]) Display the Pandas index −print("Pandas Index...", index)Fill the NaN with some specific value −print("Index object after filling NaN value...", index.fillna('Amit')) ExampleFollowing is the code −import pandas as pd import numpy as np # Creating Pandas index with some NaN values as well index = pd.Index([50, 10, 70, np.nan, ... Read More

142 Views
To remove multiples levels using the level names and return the index, use the multiIndex.droplevel(). Set the level names as parameter.At first, import the required libraries -import pandas as pdCreate a multi-index. The names parameter sets the names for the levels in the indexmultiIndex = pd.MultiIndex.from_arrays([[5, 10], [15, 20], [25, 30], [35, 40]], names=['a', 'b', 'c', 'd']) Display the multi-index −print("Multi-index...", multiIndex)Dropping multiple levels using the level names. We have passed the names of the levels to be removed as a parameter −print("Dropping multiple level...", multiIndex.droplevel(['a', 'd'])) ExampleFollowing is the code −import pandas as pd # Create a multi-index ... Read More

750 Views
To remove a level using the name of the level and return the index, use the multiIndex.droplevel() method in Pandas. Set the name of the level to be removed as parameter.At first, import the required libraries -import pandas as pdCreate a multi-index. The names parameter sets the names for the levels in the indexmultiIndex = pd.MultiIndex.from_arrays([[5, 10], [15, 20], [25, 30], [35, 40]], names=['a', 'b', 'c', 'd']) Display the multi-index −print("Multi-index...", multiIndex)Dropping a level using the level name. We have passed the name of the level to be removed as a parameter −print("Dropping a level...", multiIndex.droplevel('b')) ExampleFollowing is the code ... Read More