Found 507 Articles for Pandas

What does the align() method do in the pandas series?

Gireesha Devara
Updated on 09-Mar-2022 05:16:15

2K+ Views

The pandas Series align method is used to align two pandas series objects on basics of the same row and/or column configuration, which is done by specifying the parameters like join, axis, etc.Instead of combining the two series of objects, the pandas series align method aligns them in a specific order. This method takes 10 parameters which are “other, join='outer', axis=None, level=None, copy=True, fill_value=None, method=None, limit=None, fill_axis=0, broadcast_axis=None”. Out of these parameters other, join and axis parameters are very important. Based on these parameters the output series object alignment depends.Example 1import pandas as pd s1 = pd.Series([8, 4, 2, 1], ... Read More

How to check whether a pandas DataFrame is empty?

Gireesha Devara
Updated on 08-Mar-2022 12:04:22

6K+ Views

Use the DataFrame.empty property to check if DataFrame contains the data or not (empty or not). The DataFrame.empty attribute returns a boolean value indicating whether this DataFrame is empty or not.If the DataFrame is empty, it will return True. and it will return False If the DataFrame is not empty.Example 1In the following example, we have initialized a DataFrame with some data and then applied the empty attribute to check if the empty attribute returns False or not.# importing pandas package import pandas as pd # create an empty DataFrame df = pd.DataFrame([['a', 'b', 'c'], ['b', 'c', 'd'], ['d', ... Read More

What is ndim in pandas DataFrame?

Gireesha Devara
Updated on 08-Mar-2022 11:55:55

2K+ Views

The ndim is an attribute in the pandas DataFrame which is used to get the integer/number representation of dimensions of the given DataFrame object.As we know, the pandas DataFrame is a two-dimensional data structure that is used to store the data in a tabular format. Regardless of the number of rows and columns lengths or type of data the dimensions of the DataFrame do not affect.The output for the ndim property of pandas DataFrame is always 2.Example 1In this following example, we have applied the ndim attribute to the pandas DataFrame object “df”, this DataFrame is created with a single ... Read More

What is NDIM in the pandas Series?

Gireesha Devara
Updated on 08-Mar-2022 11:51:32

661 Views

The ndim is an attribute in the pandas series which is used to get the integer representation of dimensions of a series object.As we know, the pandas series is a 1-dimensional data structure so the output for this ndim property is always 1. It doesn’t take any input to get the dimensions. Regardless of the number of rows and columns, the ndim property always returns 1 for pandas Series.Example 1In this following example, we have applied the ndim attribute to the pandas series object “s”.# importing packages import pandas as pd import numpy as np # create pandas Series ... Read More

How to apply the slicing indexer to the pandas DataFrame.loc attribute?

Gireesha Devara
Updated on 08-Mar-2022 11:44:45

244 Views

The loc is an attribute in the pandas DataFrame constructor that is used to access the elements of the DataFrame based on row/column label indexing.The attribute .loc takes the labels of the DataFrame row and column to access the group of elements.The “.loc” attribute allows inputs like an integer value, a list of integer values, and a slicing object with integers, and boolean array, etc. And it will raise a KeyError if the specified label is not found in the DataFrame.Example 1In this following example, we have applied the slicing indexer to the loc attribute to access the values from ... Read More

How to access pandas DataFrame elements using the .loc attribute?

Gireesha Devara
Updated on 08-Mar-2022 11:39:01

4K+ Views

The “.loc” is an attribute of the pandas.DataFrame. it is used to access elements from DataFrame based on row/column label indexing. And It works similar to pandas.DataFrame “at” attribute but the difference is, the “at” attribute is used to access only a single element whereas the “loc” attribute can access a group of elements.The “.loc” attribute allows inputs like an integer value, a list of integer values, and a slicing object with integers, and boolean array, etc. And it will raise a KeyError if the specified label is not found in the DataFrame.Example 1In this following example, we created a ... Read More

What does the pandas DataFrame.columns attribute do?

Gireesha Devara
Updated on 08-Mar-2022 11:33:56

1K+ Views

The DataFrame is a pandas two-dimension data structure that is used to store the labeled data in a table format, a DataFrame has row index labels and column index labels which are used to represent the element (a value) address.By using these row/column labels we can access elements of a DataFrame and we can do data manipulations too.If you want to get the column labels from a DataFrame separately then we can use the pandas.DataFrame “columns” attribute.Example 1In this example, we have applied the columns attribute to the pandas DataFrame to get the column labels.# importing pandas package import pandas ... Read More

What does the pandas DataFrame.index attribute do?

Gireesha Devara
Updated on 08-Mar-2022 11:28:18

422 Views

A DataFrame is a pandas data structure that is used to store the labeled data in a two-dimension, the labels can be anything like text data, integer values, and time sequence. by using these labels we can access elements of a given DataFrame and we can do data manipulations too.In pandas.DataFrame the row labels are called indexes, If you want to get index labels separately then we can use pandas.DataFrame “index” attribute.Example 1In this example, we have applied the index attribute to the pandas DataFrame to get the row index labels.# importing pandas package import pandas as pd # ... Read More

How to apply the slicing indexer to the pandas DataFrame.iloc attribute?

Gireesha Devara
Updated on 08-Mar-2022 11:23:24

530 Views

The pandas DataFrame.iloc is an attribute that is used to access the elements of the DataFrame using integer-location-based index values.The attribute .iloc only takes the integer values which are specifying the row and column index positions. Generally, the position-based index values are represented from 0 to length-1.Beyond this range only we can access the DataFrame elements otherwise it will raise an “IndexError”. But the slice indexer won’t raise “IndexError” for out-of-bound index value, because it allows out-of-bounds index values.Example 1In this following example, we have applied the slicing indexer to the iloc attribute to access the values from the 1st ... Read More

How to access pandas DataFrame elements using the .iloc attribute?

Gireesha Devara
Updated on 08-Mar-2022 09:49:27

1K+ Views

The pandas.DataFrame.iloc attribute is used to access elements from a pandas DataFrame using the integer position. And It is very similar to the pandas.DataFrame “iat” attribute but the difference is, the “iloc” attribute can access a group of elements whereas the “iat” attribute accesses only a single element.The “.iloc” attribute allows inputs like an integer value, a list of integer values, and a slicing object with integers, and boolean array, etc.The attribute will raise an “IndexError” if the requested index is out of bounds, except for the slicing indexer object.Example 1In this following example, we created a pandas DataFrame using ... Read More

Advertisements