Search⌘ K
AI Features

Additional Functions and Features

Explore essential Pandas functions to calculate sums and minimum values across rows and columns, and understand multilevel indexing in Series and DataFrames. This lesson helps you manipulate complex data structures effectively for predictive data analysis using Python.

Pandas functions

The following functions are explained:

  1. sum(axis=0) : This function calculates the sum of each column of a DataFrame.

  2. sum(axis=1) : This function calculates the sum of each row of a DataFrame.

Python 3.5
import numpy as np
import pandas as pd
# Declaring DataFrame
df = pd.DataFrame(np.arange(9).reshape(3,3), index=['A', 'B', 'C'], columns=['A', 'B', 'C'])
print("The DataFrame")
print(df)
print("\nThe sum of each Column:")
print(df.sum(axis=0))
print("\nThe sum of each Row:")
print(df.sum(axis=1))

The sum of the column and row elements are clearly visible in the output.

  1. min(axis=0) : This function returns the minimum value from ...