Informatics Practices

Take a DataFrame of your choice. Write a program to calculate count of values only in a selective column.

Python Pandas

1 Like

Answer

import pandas as pd
data = {
    'Name': ['Deepika', 'Simran', 'Shivang', 'Anurag', 'Ankith'],
    'Age': [25, 30, None, 40, 45],
    'City': ['Goa', 'Kochi', 'Pondicherry', 'Rohtak', 'Kasol']
}

df = pd.DataFrame(data)
selected_column = 'Age'
count_values = df[selected_column].count()
print("Count of values in", selected_column, ":" , count_values)

Output

Count of values in Age : 4

Answered By

1 Like


Related Questions