Found 507 Articles for Pandas

Python Pandas - Return the Number of elements in the underlying Index data

AmitDiwan
Updated on 13-Oct-2021 11:22:40

93 Views

To return the Number of elements in the underlying Index data, use the index.size property 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 the number of elements in the Index −print("Number of elements in the index...", index.size) 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) ... Read More

Python Pandas - Return the Number of dimensions of the underlying data

AmitDiwan
Updated on 13-Oct-2021 11:21:43

81 Views

To return the Number of dimensions of the underlying data, use the index.ndim property.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 dimensions of the data −print("Return the dimensions...", index.ndim) 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 an array representing the data in the Index print("Array...", index.values) # Return a tuple of the shape of the underlying data ... Read More

Python Pandas - Return the number of bytes in the underlying Index data

AmitDiwan
Updated on 13-Oct-2021 11:20:56

223 Views

To return the number of bytes in the underlying Index data, use the index.nbytes property.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 bytes in the data −print("Return the bytes...", index.nbytes) 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 an array representing the data in the Index print("Array...", index.values) # Return a tuple of the shape of the underlying ... Read More

Python Pandas - Set the name of the index

AmitDiwan
Updated on 13-Oct-2021 11:19:01

3K+ Views

To set the name of the index, use the index.set_names() and include the name of the index as an argument.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane']) Display the index −print("Pandas Index...", index)Set the index name −print("Index name...", index.set_names('Vehicle')) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane']) # Display the index print("Pandas Index...", index) # Return an array representing the data in the Index print("Array...", index.values) # Set the index name print("Index name...", index.set_names('Vehicle'))OutputThis ... Read More

Python Pandas - Return a tuple of the shape of the underlying data

AmitDiwan
Updated on 13-Oct-2021 11:18:16

459 Views

To return a tuple of the shape of the underlying data, use the index.shape property in Pandas.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane']) Display the index −print("Pandas Index...", index)Return a tuple of the shape of the underlying data −print("A tuple of the shape of underlying data...", index.shape) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane']) # Display the index print("Pandas Index...", index) # Return an array representing the data in the Index print("Array...", index.values) ... Read More

Python Pandas - Return a string of the type inferred from the values

AmitDiwan
Updated on 13-Oct-2021 11:17:36

94 Views

To return a string of the type inferred from the values, use the index.inferred_type property in Pandas.At first, import the required libraries −import pandas as pd import numpy as npCreating the index. For NaN, we have used numpy library −index = pd.Index(['Car', 'Bike', np.nan, 'Car', np.nan, 'Ship', None, None]) Display the index −print("Pandas Index...", index)Return a string of the type inferred from the values −print("The inferred type...", index.inferred_type) ExampleFollowing is the code −import pandas as pd import numpy as np # Creating the index # For NaN, we have used numpy library index = pd.Index(['Car', 'Bike', np.nan, 'Car', np.nan, ... Read More

Python Pandas - Return the dtype object of the underlying data

AmitDiwan
Updated on 13-Oct-2021 11:15:56

347 Views

To return the dtype object of the underlying data, use the index.dtype property in Pandas.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index(['Car', 'Bike', 'Shop', 'Car', 'Airplace', 'Truck']) Display the index −print("Pandas Index...", index)Return the dtype of the data −print("The dtype object...", index.dtype) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index(['Car', 'Bike', 'Shop', 'Car', 'Airplace', 'Truck']) # Display the index print("Pandas Index...", index) # Return an array representing the data in the Index print("Array...", index.values) # Return the dtype of the data print("The ... Read More

Python Pandas - Check if the index has NaNs

AmitDiwan
Updated on 13-Oct-2021 11:14:33

1K+ Views

To check if the index has NaNs, use the index.hasnans property in Pandas.At first, import the required libraries −import pandas as pd import numpy as npCreating the index. For NaN, we have used numpy library −index = pd.Index(['Car', 'Bike', np.nan, 'Car', np.nan, 'Ship']) Display the index −print("Pandas Index...", index)Check if the index is having NaNs −print("Is the Pandas index having NaNs?", index.hasnans) ExampleFollowing is the code −import pandas as pd import numpy as np # Creating the index # For NaN, we have used numpy library index = pd.Index(['Car', 'Bike', np.nan, 'Car', np.nan, 'Ship']) # Display the ... Read More

Python Pandas - Check if the index has duplicate values

AmitDiwan
Updated on 13-Oct-2021 11:13:11

4K+ Views

To check if the index has duplicate values, use the index.has_duplicates property in Pandas.At first, import the required libraries −import pandas as pdCreating the index −index = pd.Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane']) Display the index −print("Pandas Index...", index)Check if the index is having duplicate values −print("Is the Pandas index having duplicate values?", index.has_duplicates) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane']) # Display the index print("Pandas Index...", index) # Return an array representing the data in the Index print("Array...", index.values) # Check if the index ... Read More

Python Pandas - Check if the index has unique values

AmitDiwan
Updated on 13-Oct-2021 11:11:26

3K+ Views

To check if the index has unique values, use the index.is_unique.At first, import the required libraries −import pandas as pdLet us create the index −index = pd.Index([50, 40, 30, 20, 10]) Display the index −print("Pandas Index...", index)Check if the index is having unique values −print("Is the Pandas index having unique values?", index.is_unique) ExampleFollowing is the code −import pandas as pd # Creating the index index = pd.Index([50, 40, 30, 20, 10]) # Display the index print("Pandas Index...", index) # Return an array representing the data in the Index print("Array...", index.values) # Check if the index is ... Read More

Advertisements