I. 何をする?

Moodleのアクティビティ「小テスト」を用いて作成したアンケートの結果を集計します。

II. Exploratoryの場合

RのExploratoryを使用するのが最も簡単です。手順は次です。

  1. Exploratoryをダウンロード、インストールする。

  2. Moodleのアクティビティ「小テスト」の解答をCSVでダウンロードする。日本語でもかまわない。

  3. Exploratoryに読み込む。

次のグラフが作成されます。プログラムの知識は必要ありません。

III. Pythonの場合

Python+plotly+streamlit+HerokuでWebアプリとして公開します。

Moodleの言語設定を英語にして、データのCSVファイルをダウンロードします。

Pandasで読み込み、列名を表示します。

# ライブラリをインポート
import pandas as pd
import janitor
import matplotlib.pyplot as plt
# データを読み込む
df = pd.read_csv('data/2021w1qnn.csv')
# 列名を表示
print(df.columns)
## Index(['Surname', 'First name', 'ID number', 'State', 'Started on',
##        'Completed', 'Time taken', 'Grade/10.00', 'Question 1', 'Response 1',
##        'Question 2', 'Response 2', 'Question 3', 'Response 3', 'Question 4',
##        'Response 4', 'Question 5', 'Response 5', 'Question 6', 'Response 6',
##        'Question 7', 'Response 7', 'Question 8', 'Response 8'],
##       dtype='object')

列名をjanitorでクリーンにし、列名を表示します。

# 列名をクリーンに
df_cleaned = janitor.clean_names(df)
# 列名を表示
print(df_cleaned.columns)
## Index(['surname', 'first_name', 'id_number', 'state', 'started_on',
##        'completed', 'time_taken', 'grade_10_00', 'question_1', 'response_1',
##        'question_2', 'response_2', 'question_3', 'response_3', 'question_4',
##        'response_4', 'question_5', 'response_5', 'question_6', 'response_6',
##        'question_7', 'response_7', 'question_8', 'response_8'],
##       dtype='object')

for loopsを用いて各列の各選択肢の頻度を集計します。

# 回答1-7列を取り出す
df1 = df_cleaned.iloc[:, [9, 11, 13, 15, 17, 19, 21]]
# show frequencies
mylist = ['response_1', 'response_2', 'response_3', 'response_4', 'response_5', 'response_6', 'response_7']
for ls in mylist:
  results = df1[ls].value_counts()
  print(results)
## スマートフォン(iPhone)    14
## コンピュータ(Windows)     4
## コンピュータ(Mac)         2
## タブレット(iPad)         1
## Name: response_1, dtype: int64
## どちらかというとそう思う      9
## どちらともいえない         6
## どちらかというとそう思わない    3
## そう思う              3
## Name: response_2, dtype: int64
## どちらかというとそう思う    13
## そう思う             5
## どちらともいえない        3
## Name: response_3, dtype: int64
## 使ったことがない。                                      14
## 足し算(たしざん)や掛け算(かけざん)など簡単な計算ができる。                 4
## 使ったことがない。; 足し算(たしざん)や掛け算(かけざん)など簡単な計算ができる。      1
## sum関数を使える。                                      1
## 足し算(たしざん)や掛け算(かけざん)など簡単な計算ができる。; sum関数を使える。     1
## Name: response_4, dtype: int64
## どちらかというとそう思う      11
## どちらともいえない          4
## どちらかというとそう思わない     3
## そう思う               3
## Name: response_5, dtype: int64
## どちらかというとそう思う      8
## どちらともいえない         4
## どちらかというとそう思わない    4
## そう思う              4
## そう思わない            1
## Name: response_6, dtype: int64
## どちらかというとそう思う      9
## そう思う              6
## どちらともいえない         4
## どちらかというとそう思わない    1
## そう思わない            1
## Name: response_7, dtype: int64

回答の一つ目の頻度のバー・チャートを作成します。

# use fonts for Japanese
plt.rcParams['font.family'] = 'Hiragino Maru Gothic Pro'
# create a bar chart
df1['response_1'].value_counts().plot(kind='bar') 
plt.xticks(rotation=10)
## (array([0, 1, 2, 3]), [Text(0, 0, 'スマートフォン(iPhone)'), Text(1, 0, 'コンピュータ(Windows)'), Text(2, 0, 'コンピュータ(Mac)'), Text(3, 0, 'タブレット(iPad)')])
plt.ylabel("number",  fontsize=18)
plt.title("遠隔授業の場合に何を使いますか?")
plt.show()