Skip to content
background-image background-image

Analyzing Customer Survey Data from CSV Using Pandas

This example demonstrates the use of Python's Pandas library to extract and analyze customer survey data provided in CSV format.



Imagine you are a data analyst at a small online bookstore called "BookHaven." Your team is interested in analyzing the sales data of different book genres to make informed decisions about inventory management and marketing strategies.


The team recently conducted a customer survey, and you've received a CSV-formatted string containing survey responses. Each row in the CSV represents a customer's response, including their name, age, favorite book genre, and whether they've made a purchase in the past month. Your task is to extract and analyze this data using Pandas.


On input data, we have a CSV-formatted string with the following structure:

David,45,Science Fiction,Yes
Emily,29,Science Fiction,Yes

Input data has the following structure:

"data": string

import pandas as pd
from io import StringIO

# Convert the CSV string into a Pandas DataFrame
data = pd.read_csv(StringIO(INPUT_DATA[0]["data"]))

# Display the first few rows of the DataFrame

# Analyze the data
total_customers = len(data)
purchased_customers = len(data[data["Has_Purchased"] == "Yes"])
average_age = data["Age"].mean()

# Analysis Results"Total Customers: {total_customers}")"Customers Who Made a Purchase: {purchased_customers}")"Average Age of Customers: {average_age:.2f} years")


  • Converting CSV to DataFrame: We use Pandas to read the CSV string and convert it into a DataFrame for easy data manipulation.
  • Displaying Data: We display the first few rows of the DataFrame to understand the structure of the data.
  • Data Analysis: We calculate and log key statistics such as the total number of customers, the number of customers who made a purchase, and the average age of customers.


This Pandas-based analysis of customer survey data enables data analysts to extract insights quickly and efficiently. By leveraging Pandas' capabilities, you can explore and understand your data, which can inform decisions related to inventory management and marketing strategies for your online bookstore or similar businesses.