In [19]:
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import numpy as np
import matplotlib.pyplot as plt
# Đọc dữ liệu từ file exel
df = pd.read_excel('Sample_Responses_clean.xlsx')
# In ra tên của các cột, nếu cần
# print("Tên cột:")
# print(df.columns)
# Xóa bỏ các hàng không có dữ liệu
df = df.dropna()
# Lấy dữ liệu theo tên cột
Tuoi = df['Tuổi']
So_luong_mon_hoc_truc_tuyen = df['Số lượng môn học mà bạn đang học trực tuyến?']
# Vẽ biểu đồ hiển thị số liệu dạng scatter plot
plt.scatter(Tuoi, So_luong_mon_hoc_truc_tuyen)
plt.xlabel('Tuổi', fontsize = 14)
plt.ylabel ('Số lượng môn học trực tuyến', fontsize = 14)
plt.title ('Biểu đồ scatter giữa số lượng môn học và số tuổi', fontsize = 16)
plt.show()
# Vẽ biểu đồ hiển thị số liệu dạng historam
so_gio_hoc_tap_moi_ngay = df['SỐ GIỜ MỖI NGÀY Bạn dành khoảng thời gian bao lâu để sử dụng internet cho mục đích học tập?']
so_gio_khac_moi_ngay = df['SỐ GIỜ MỖI NGÀY, bạn dành khoảng thời gian bao lâu để sử dụng internet cho mục đích khác (ví dụ lướt web)?']
colors = ['red', 'tan']
_label = ['học tập', 'giải trí']
plt.hist([so_gio_hoc_tap_moi_ngay, so_gio_khac_moi_ngay], histtype='bar', color=colors, label=_label)
plt.xlabel('Số giờ học tập/giải trí mỗi ngày qua internet', fontsize = 14)
plt.ylabel ('Số lượng người tham gia ks', fontsize = 14)
plt.legend(prop={'size': 10})
plt.title ('Biểu đồ histogram số giờ học mỗi ngày sử dụng internet', fontsize = 16)
plt.show()
In [1]:
import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile
import numpy as np
import matplotlib.pyplot as plt
# Đọc dữ liệu từ file exel
df = pd.read_excel('AAA.xlsx')
new_df = df.iloc[:,[1,4,5,6,7,8,9]]
new_df.rename(columns={"Tuổi": "tuoi", "Giới tính": "gioitinh"})
# w.female[w.female == 'female'] = 1
# w.female[w.female == 'male'] = 0
new_1_df = new_df.rename(columns={"Tuổi": "tuoi", "Giới tính ": "gioitinh", \
"Bạn đang sử dụng thiết bị nào để học trực tuyến? (có thể chọn tất cả các phương án phù hợp)": "thietbi",\
"Bạn dùng ứng dụng nào để tham gia học trực tuyến (chọn tất cả các phương án phù hợp)": "ungdung"})
# print (len(set(new_1_df.thietbi)), set(new_1_df.thietbi))
print ("Thiet bi su dung")
for i, name in enumerate(set(new_1_df.thietbi)):
print ("%s: %s"%(i, name))
new_1_df.thietbi[new_1_df.thietbi == name] = i
print ("Ung dung su dung")
for i, name in enumerate(set(new_1_df.ungdung)):
print ("%s: %s"%(i, name))
new_1_df.thietbi[new_1_df.ungdung == name] = i
# In ra de xem
print (new_1_df)
In [ ]: