【问题标题】:How to transform Pandas dataframe for likert scale visualization?如何转换 Pandas 数据框以实现李克特规模可视化?
【发布时间】:2022-11-10 17:43:03
【问题描述】:

我正在分析一项调查。这包含李克特量表。要使用 Plotly 显示它们(请参阅 link),我需要适当的格式。因此我的问题是,我如何从以下格式中得到:

到这个目标格式:

源数据框:

    {
        "ID": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
        "Q1": [
            "no answer",
            "Very satisfied",
            "no answer",
            "no answer",
            "Very satisfied",
            "no answer",
            "no answer",
            "Very satisfied",
            "Very satisfied",
            "no answer",
            "no answer",
            "Neither satisfied nor dissatisfied",
            "no answer",
            "Very satisfied",
            "Neither satisfied nor dissatisfied",
            "Somewhat satisfied",
        ],
        "Q2": [
            "no answer",
            "Very satisfied",
            "no answer",
            "no answer",
            "Very satisfied",
            "no answer",
            "no answer",
            "Very satisfied",
            "Very satisfied",
            "no answer",
            "no answer",
            "Somewhat satisfied",
            "no answer",
            "Very satisfied",
            "Somewhat dissatisfied",
            "Neither satisfied nor dissatisfied",
        ],
        "Q3": [
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "no answer",
            "Neither satisfied nor dissatisfied",
            "no answer",
            "Somewhat satisfied",
        ],
    }
) 

【问题讨论】:

    标签: python plotly analysis survey likert


    【解决方案1】:

    你可以这样做:

    pd.concat([df[c].value_counts() for c in df.columns[1:]],axis=1).fillna(0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-29
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 2020-12-26
      相关资源
      最近更新 更多