End-to-End Survey Data Simulation and Analysis on TSSFL Technology Stack

Concepts and Principles: Definitions of Data Science, the Data Science lifecycle, different roles in Data Science, ethical considerations, data governance, introduction to various tools and technologies used in Data Science.
Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 189
Posts: 5974
Joined: 10 years ago
Location: Tanzania
Contact:

#1

🔍 Summary

Hi everyone,

I’d like to share a simple Python script that generates mock data for pre- and post-intervention surveys. This can be useful for anyone working on research, program evaluation, or simulations where realistic survey data is needed for testing or demonstration purposes.

📝 Survey Setup
  • Number of Respondents: 100
  • Number of Questions: 16
  • Response Options (Likert Scale):
    • Strongly Disagree
    • Disagree
    • Somewhat Agree
    • Agree
    • Strongly Agree
Each question is treated as a column, and each respondent occupies a row in the dataset.

📁 Output

The script generates four files:
  • pre_survey.xlsx
  • post_survey.xlsx
  • pre_survey.csv
  • post_survey.csv
These files contain randomly generated responses simulating answers before and after an intervention.


Python Script

  1. import pandas as pd
  2. import numpy as np
  3.  
  4. #Define parameters
  5. num_questions = 16
  6. num_respondents = 100
  7. response_options = ["Strongly Disagree", "Disagree", "Somewhat Agree", "Agree", "Strongly Agree"]
  8.  
  9. # Generate column names for questions
  10. question_columns = [f"Q{i+1}" for i in range(num_questions)]
  11.  
  12. # Generate random responses for pre and post surveys
  13. pre_survey_data = pd.DataFrame({
  14.     question: np.random.choice(response_options, size=num_respondents)
  15.     for question in question_columns
  16. })
  17.  
  18. post_survey_data = pd.DataFrame({
  19.     question: np.random.choice(response_options, size=num_respondents)
  20.     for question in question_columns
  21. })
  22.  
  23. # Save to Excel and CSV files
  24. pre_survey_data.to_excel("pre_survey.xlsx", index=False)
  25. post_survey_data.to_excel("post_survey.xlsx", index=False)
  26. pre_survey_data.to_csv("pre_survey.csv", index=False)
  27. post_survey_data.to_csv("post_survey.csv", index=False)


Feel free to adapt the script to your specific use case - such as changing the number of respondents or using a custom set of questions.

You can generate the dataset by running the Python code at AI-Assisted Live Programming and Computing with Python, R, Sage, Octave, Maxima, Singular, Gap, GP, HTML & Macaulay2

And test the datasets with our app - Survey Insights Generator.

Let me know if you have any questions or suggestions!
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Data Science Fundamentals”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests