首页 > 解决方案 > AttributeError:“DataFrame”对象没有属性“question_response”

问题描述

我正在尝试为以下数据集绘制条形图

                                                                                          qr_count
question_title                                                    question_response
The course recommended books etc. are relevant and appropriate:          agree               116
The course workload is manageable:                                       agree               112
I think I have made progress in the course:                              agree               111
The Course is well organized / updated :                                 agree               103
The course contents increased my knowledge of the subject:               agree               103

我已经使用这种方法从另一个数据帧中提取了这个数据帧

 each_qt_count = new_merge_data[['question_title', 'question_response']].value_counts()
each_qt_count = pd.DataFrame(each_qt_count)
each_qt_count.rename(columns={0:'qr_count'}, inplace=True)
each_qt_count.head()

new_merge_data 具有以下行

Index(['question_id', 'question_title', 'course_title', 'course_code',
   'course_assign_id', 'id', 'question_response', 'student_id',
   'date_created'],
  dtype='object')

现在我正在尝试使用这种方法绘制 each_qt_count

plt.bar(each_qt_count.question_response, each_qt_count.qr_count)

它给了我这个错误

AttributeError:“DataFrame”对象没有属性“question_response”

请帮助我如何为这个数据框绘制条形图?

提前致谢

标签: pandasdataframepython-3.7

解决方案


推荐阅读