How to print the value counts of a user-selected column in a pandas DataFrame?

7 hours ago 2
ARTICLE AD BOX

I’m trying to write a Python script that allows the user to input the name of a column and then prints the value counts of that column from a pandas DataFrame. Here’s what I currently have:

def count_unique_values(df, column_list): for col in column_list: if col not in df.columns: print(f"Column '{col}' not found in the DataFrame.\n") continue print(f"\nColumn: {col}") counts = df[col].value_counts() print(counts, "\n") print(col=input("Input column name: ")
Read Entire Article