Write a Python program to find the mean, median, and mode of a numerical column in a DataFrame.

SOLUTION .

import pandas as pd

# Taking dynamic input for the number of values
n = int(input("Enter the number of values: "))

# Taking dynamic input for numerical data
data = [float(input(f"Enter value {i+1}: ")) for i in range(n)]

# Creating a DataFrame
df = pd.DataFrame({'Numbers': data})

# Calculating mean, median, and mode
mean_value = df['Numbers'].mean()
median_value = df['Numbers'].median()
mode_value = df['Numbers'].mode()

# Displaying the results
print("\nDataFrame:\n", df)
print("\nMean:", mean_value)
print("Median:", median_value)
print("Mode:\n", mode_value)
    

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.