关于 survey-analyzer
Survey Analyzer 是一款用于分析问卷数据的 Python 工具,涵盖量表、分类和开放式回答,并结合统计分析、可视化、细分比较及 PDF 或 HTML 报告生成。
主要功能
- 01Likert 量表和频率分析
- 02交叉表与统计检验
- 03情感和主题分析
- 04图表、热图和词云
- 05细分和趋势分析
- 06生成 PDF 和 HTML 报告
适用场景
- 01汇总满意度和 Likert 回答
- 02检验问卷分类变量之间的关系
- 03分析评论中的主题和情感
- 04比较不同细分群体或时段的回答模式
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ dkyazzentwatwa/ chatgpt-skills --skill survey-analyzer安装后在 Claude Code 中输入/survey-analyzer确认已加载。
附带文件scripts/requirements.txtscripts/survey_analyzer.py
详细介绍
调查分析器
全面的调查数据分析,涵盖李克特量表、交叉表和情感分析。
功能
- 李克特量表分析:同意度量表评分和可视化
- 交叉列表:分析分类变量之间的关系
- 频率分析:回答分布和百分比
- 情感评分:文本回答情感分析
- 开放式回答分析:从文本回答中提取主题
- 统计检验:卡方检验、相关性和显著性检验
- 可视化:条形图、热力图、词云和分布图
- 报告生成:全面的 PDF/HTML 报告
快速开始
from survey_analyzer import SurveyAnalyzer
analyzer = SurveyAnalyzer()
# Load survey data
analyzer.load_csv('survey_responses.csv')
# Analyze Likert scale question
results = analyzer.likert_analysis('satisfaction', scale_type='agreement')
print(f"Mean score: {results['mean_score']:.2f}")
# Cross-tabulation
crosstab = analyzer.crosstab('age_group', 'product_preference')
print(crosstab)
# Generate report
analyzer.generate_report('survey_report.pdf')
CLI 用法
# Analyze Likert scale
python survey_analyzer.py --data survey.csv --likert satisfaction --output results.pdf
# Cross-tabulation
python survey_analyzer.py --data survey.csv --crosstab age_group product --output crosstab.png
# Sentiment analysis
python survey_analyzer.py --data survey.csv --sentiment comments --output sentiment.html
# Full report
python survey_analyzer.py --data survey.csv --report --output full_report.pdf
API 参考
SurveyAnalyzer 类
class SurveyAnalyzer:
def __init__(self)
# Data Loading
def load_csv(self, filepath, **kwargs) -> 'SurveyAnalyzer'
def load_data(self, data: pd.DataFrame) -> 'SurveyAnalyzer'
# Likert Scale Analysis
def likert_analysis(self, column, scale_type='agreement') -> Dict
def likert_comparison(self, columns: List[str]) -> pd.DataFrame
def plot_likert(self, column, output, scale_type='agreement') -> str
# Frequency Analysis
def frequency_table(self, column) -> pd.DataFrame
def multiple_choice(self, column, delimiter=',') -> pd.DataFrame
def plot_frequencies(self, column, output, top_n=None) -> str
# Cross-Tabulation
def crosstab(self, row_var, col_var, normalize=None) -> pd.DataFrame
def chi_square_test(self, row_var, col_var) -> Dict
def plot_crosstab(self, row_var, col_var, output) -> str
# Sentiment Analysis
def sentiment_analysis(self, column) -> pd.DataFrame
def sentiment_summary(self, column) -> Dict
def plot_sentiment(self, column, output) -> str
# Open-Ended Analysis
def word_frequency(self, column, top_n=20) -> pd.DataFrame
def word_cloud(self, column, output) -> str
def extract_themes(self, column, n_themes=5) -> List[str]
# Statistics
def satisfaction_score(self, columns: List[str]) -> Dict
def response_rate(self) -> Dict
def demographics_summary(self, columns: List[str]) -> pd.DataFrame
# Reporting
def generate_report(self, output, format='pdf') -> str
def summary(self) -> str
李克特量表分析
标准量表
# 5-point agreement scale
analyzer.likert_analysis('satisfaction', scale_type='agreement')
# 1=Strongly Disagree, 2=Disagree, 3=Neutral, 4=Agree, 5=Strongly Agree
# 5-point frequency scale
analyzer.likert_analysis('usage', scale_type='frequency')
# 1=Never, 2=Rarely, 3=Sometimes, 4=Often, 5=Always
# Custom scale
analyzer.likert_analysis('rating', scale_type='custom',
labels=['Poor', 'Fair', 'Good', 'Excellent'])
结果
results = analyzer.likert_analysis('satisfaction')
# {
# 'mean_score': 4.2,
# 'median': 4,
# 'mode': 5,
# 'distribution': {1: 2, 2: 5, 3: 15, 4: 40, 5: 38},
# 'percentages': {1: 2%, 2: 5%, 3: 15%, 4: 40%, 5: 38%},
# 'top_2_box': 78%, # % Agree + Strongly Agree
# 'bottom_2_box': 7% # % Disagree + Strongly Disagree
# }
可视化
# Stacked bar chart
analyzer.plot_likert('satisfaction', 'likert_chart.png')
# Compare multiple questions
analyzer.likert_comparison(['quality', 'value', 'service'])
analyzer.plot_likert_comparison(['quality', 'value', 'service'],
'comparison.png')
频率分析
单选题
freq = analyzer.frequency_table('age_group')
# Count Percentage
# 18-24 45 22.5%
# 25-34 78 39.0%
# 35-44 52 26.0%
# 45+ 25 12.5%
# Plot
analyzer.plot_frequencies('age_group', 'age_distribution.png')
多选题
对于允许多选的问题:
# Data format: "Option A, Option B, Option C"
results = analyzer.multiple_choice('features_liked', delimiter=',')
# Count Percentage
# Price 120 60%
# Quality 95 47.5%
# Design 80 40%
# Durability 70 35%
analyzer.plot_frequencies('features_liked', 'features.png', top_n=10)
交叉列表
基本交叉表
crosstab = analyzer.crosstab('age_group', 'satisfaction')
# Satisfied Neutral Dissatisfied
# 18-24 30 10 5
# 25-34 60 15 3
# 35-44 40 8 4
# 45+ 18 5 2
# With percentages
crosstab_pct = analyzer.crosstab('age_group', 'satisfaction',
normalize='index') # Row percentages
统计检验
result = analyzer.chi_square_test('age_group', 'satisfaction')
# {
# 'statistic': 12.45,
# 'p_value': 0.014,
# 'significant': True,
# 'interpretation': 'There is a significant relationship between
# age_group and satisfaction (p=0.014)'
# }
可视化
# Heatmap
analyzer.plot_crosstab('age_group', 'satisfaction', 'crosstab_heatmap.png')
情感分析
分析开放式文本回答:
# Analyze all comments
sentiment_df = analyzer.sentiment_analysis('comments')
# comment polarity sentiment
# 0 "Great product!" 0.8 Positive
# 1 "Could be better" 0.1 Neutral
# 2 "Very disappointed" -0.6 Negative
# Summary
summary = analyzer.sentiment_summary('comments')
# {
# 'positive': 65%,
# 'neutral': 20%,
# 'negative': 15%,
# 'avg_polarity': 0.35
# }
# Visualize
analyzer.plot_sentiment('comments', 'sentiment_distribution.png')
开放式回答分析
词频
words = analyzer.word_frequency('comments', top_n=20)
# Word Frequency
# 0 great 45
# 1 quality 38
# 2 price 32
# ...
词云
analyzer.word_cloud('comments', 'wordcloud.png')
主题提取
themes = analyzer.extract_themes('feedback', n_themes=5)
# ['product quality', 'customer service', 'pricing',
# 'delivery speed', 'user experience']
满意度指标
净推荐值(NPS)
nps = analyzer.nps_score('recommendation') # 0-10 scale
# {
# 'promoters': 65%, # 9-10
# 'passives': 25%, # 7-8
# 'detractors': 10%, # 0-6
# 'nps': 55
# }
总体满意度
satisfaction = analyzer.satisfaction_score([
'product_quality',
'customer_service',
'value_for_money',
'ease_of_use'
])
# {
# 'overall_score': 4.3,
# 'category_scores': {...},
# 'satisfaction_rate': 86% # % scoring 4-5
# }
人口统计分析
demographics = analyzer.demographics_summary([
'age_group',
'gender',
'location',
'income_range'
])
# Returns frequency tables for each demographic variable
回答率分析
response_rate = analyzer.response_rate()
# {
# 'total_respondents': 200,
# 'completion_rate': 85%,
# 'average_time': '5m 30s',
# 'dropout_points': {
# 'question_5': 8%,
# 'question_12': 5%
# }
# }
报告生成
综合报告
analyzer.generate_report('survey_report.pdf', format='pdf')
报告包括:
- 执行摘要
- 回答率和人口统计信息
- 逐题分析
- 李克特量表可视化
- 交叉表
- 情感分析
- 关键发现和建议
自定义报告部分
analyzer.set_report_sections([
'executive_summary',
'demographics',
'likert_questions',
'cross_tabs',
'sentiment',
'recommendations'
])
高级功能
按细分群体筛选
# Analyze subset of responses
analyzer.filter('age_group', '25-34')
results = analyzer.likert_analysis('satisfaction')
analyzer.clear_filter()
比较细分群体
comparison = analyzer.compare_segments(
segment_col='age_group',
metric_col='satisfaction'
)
# Shows how different segments scored the metric
趋势分析
用于纵向调查:
trends = analyzer.trend_analysis(
metric='satisfaction',
time_col='survey_date',
period='month'
)
analyzer.plot_trends(trends, 'satisfaction_trend.png')
依赖项
- pandas>=2.0.0
- numpy>=1.24.0
- scipy>=1.10.0
- textblob>=0.17.0
- matplotlib>=3.7.0
- seaborn>=0.12.0
- wordcloud>=1.9.0
- reportlab>=4.0.0
评论
支持 Markdown