Informatics Practices
Take a DataFrame of your choice. Write a program to calculate count of values only in a selective column.
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
Related Questions
Write a program to print a DataFrame one row at a time and print only first five rows.
Write a program that performs count, sum, max, and min functions :
On rows
On columns
Give two identical DataFrames Sales16 and Sales17. But Sales17 has some values missing. Write code so that Sales17 fills its missing values from the corresponding entries of Sales16.
Write code that just produces single True/False as a result for the presence of missing values in whole DataFrame namely df.