Python Articles

Page 78 of 855

What happens if the specified index is not present in the series Python Pandas?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 676 Views

When the index values are customized, they are accessed using series_name[‘index_value’]. The ‘index_value’ passed to series is tried to be matched to the original series. If it is found, that corresponding data is also displayed on the console.When the index that is tried to be accessed is not present in the series, it throws an error. It has been shown below.Exampleimport pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) print("Accessing elements using customized index") print(my_series['mm'])OutputThe series contains ...

Read More

Explain how a dataframe structure can be created using list of dictionary values in Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 174 Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation.It can be created using the following constructor −pd.Dataframe(data, index, columns, dtype, copy)The ‘data’, ‘index’, ‘columns’, ‘dtype’ and ‘copy’ are not compulsory values.A list of dictionaries can be passed as input to the dataframe. The keys of dictionary are taken as column names by default. Let us see an example −Exampleimport pandas as pd my_data = [{'ab' : 34}, {'mn' : 56}, { 'gh' : 78}, ...

Read More

How can a column of a dataframe be deleted in Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 181 Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. A column in a dataframe can be deleted using different methods.We will see the ‘del’ operator that takes the name of the column that needs to be deleted as a parameter, and deletes it −Exampleimport pandas as pd my_data = {'ab' : pd.Series([1, 8, 7], index=['a', 'b', 'c']), 'cd' : pd.Series([1, 2, 0, 9], index=['a', 'b', 'c', 'd']), 'ef' : pd.Series([56, 78, 32], index=['a', 'b', ...

Read More

How to delete a column of a dataframe using the 'pop' function in Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 367 Views

Dataframe is a two dimensional data structure, where data is stored in a tabular format, in the form of rows and columns.It can be visualized as an SQL data table or an excel sheet representation. A column in a dataframe can be deleted using different methods.We will see the pop function that takes the name of the column that needs to be deleted as a parameter, and deletes it.Exampleimport pandas as pd my_data = {'ab' : pd.Series([1, 8, 7], index=['a', 'b', 'c']), 'cd' : pd.Series([1, 2, 0, 9], index=['a', 'b', 'c', 'd']), 'ef' : pd.Series([56, 78, 32], index=['a', 'b', 'c']), ...

Read More

How to get the sum of a specific column of a dataframe in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Sometimes, it may be required to get the sum of a specific column. This is where the ‘sum’ function can be used.The column whose sum needs to be computed can be passed as a value to the sum function. The index of the column can also be passed to find the sum.Let us see a demonstration of the same −Exampleimport pandas as pd my_data = {'Name':pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20]) } print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The sum of 'age' column is :") print(my_df.sum(1))OutputThe dataframe is : ...

Read More

How to get the mean of columns that contains numeric values of a dataframe in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Sometimes, it may be required to get the mean values of a specific column or mean values of all columns that contains numerical values. This is where the mean() function can be used.The term ‘mean’ refers to finding the sum of all values and dividing it by the total number of values in the dataset.Let us see a demonstration of the same −Exampleimport pandas as pd my_data = {'Name':pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20]) } print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The mean is :") print(my_df.mean())OutputThe dataframe is : ...

Read More

How to find the standard deviation of specific columns in a dataframe in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 7K+ Views

Standard deviation tells about how the values in the dataset are spread. They also tells how far the values in the dataset are from the arithmetic mean of the columns in the dataset.Sometimes, it may be required to get the standard deviation of a specific column that is numeric in nature. This is where the std() function can be used. The column whose mean needs to be computed can be indexed to the dataframe, and the mean function can be called on this using the dot operator.The index of the column can also be passed to find the standard deviation.Let ...

Read More

How can data be summarized in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 181 Views

Lots of information about the data can be obtained by using different functions on it. But if we wish to get all information on the data, the ‘describe’ function can be used.This function will give information such as ‘count’, ‘mean’, ‘standard deviation’, the 25th percentile, the 50th percentile, and the 75th percentile.Exampleimport pandas as pd my_data = {'Name':pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20]) } print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The description of data is :") print(my_df.describe())OutputThe dataframe is :    Name  Age   value 0  Tom   45 ...

Read More

How can a specific operation be applied row wise or column wise in Pandas Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 458 Views

It may sometimes be required to apply certain functions along the axes of a dataframe. The axis can be specified, otherwise the default axis is considered as column-wise, where every column is considered as an array.If the axis is specified, then the operations are performed row-wise on the data.The ‘apply’ function can be used in conjunction with the dot operator on the dataframe. Let us see an example −Exampleimport pandas as pd import numpy as np my_data = {'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20])} print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The description of data ...

Read More

How to apply functions element-wise in a dataframe in Python?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

It may sometimes be required to apply certain functions along the elements of the dataframe. All the functions can’t be vectorised. This is where the function ‘applymap’ comes into picture.This takes a single value as input and returns a single value as output.Exampleimport pandas as pd import numpy as np my_df = pd.DataFrame(np.random.randn(5, 5), columns=['col_1', 'col_2', 'col_3', 'col_4', 'col_5']) print("The dataframe generated is ") print(my_df) my_df.applymap(lambda x:x*11.45) print("Using the applymap function") print(my_df.apply(np.mean))OutputThe dataframe generated is     col_1       col_2      col_3      col_4     col_5 0  -0.671510  -0.860741   0.886484   0.842158   2.182341 ...

Read More
Showing 771–780 of 8,547 articles
« Prev 1 76 77 78 79 80 855 Next »
Advertisements