python 在课程表中阅读的脚本Excel电子表格并输出可视日历。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 在课程表中阅读的脚本Excel电子表格并输出可视日历。相关的知识,希望对你有一定的参考价值。

"""
Script to read in a course schedule Excel spreadsheet and output a visual calendar
"""
def time_to_float(time_str):
    if time_str is '':
        return None
    t = time_str.split(':')
    return float(t[0]) + float(t[1])/60.


# Read and parse CSV file
import csv
f = open('course_schedule.csv','rU')
reader = csv.reader(f,dialect=csv.excel_tab)
data = []
for row in reader:
    data.append(row[0].split(','))
f.close()

# Create data structure
headers = data[0]
name_ind = headers.index('Event Pack')
time_ind = headers.index('Start Time')
days = ['Sun','Mon','Tue','Wed','Thu']
courses = {}
times = []

for course in data[1:]:
    courses[course[name_ind]] = {}
    courses[course[name_ind]]['time'] = time_to_float(course[time_ind])
    times.append(time_to_float(course[time_ind]))
    courses[course[name_ind]]['days'] = []
    for day in days:
        if day in course:
            courses[course[name_ind]]['days'].append(day)

times = list(set(times))
times.remove(None)
times.sort()

# Plot calendar
import matplotlib.pyplot as plt
plt.figure(figsize=(18,12),facecolor='white')
ndays = float(len(days))+1
ntimes = float(len(times))+1

for i,day in enumerate(days):
    plt.text((i+1)/ndays,0.99,day)

for i,time in enumerate(times):
    plt.text(0.01,1.-(i+1)/ntimes,time)

import numpy as np
count = np.zeros((ntimes-1,ndays-1)) # number of classes in each slot

avoid = ['AMCS 211','AMCS 251','AMCS 231','AMCS 241']

for course_name,course in courses.iteritems():
    if True:
        for day in course['days']:
            iday = days.index(day)
            itime = times.index(course['time'])

            xloc = (1+iday)/ndays
            yloc = 1.-(1+itime)/ntimes - 0.02*count[itime,iday]
            if course_name in avoid:
                color = 'red'
            else:
                color = 'grey'
            plt.text(xloc,yloc,course_name,fontsize=12,color=color)
            count[itime,iday] += 1

plt.axis('off')
plt.show()

以上是关于python 在课程表中阅读的脚本Excel电子表格并输出可视日历。的主要内容,如果未能解决你的问题,请参考以下文章

python Lazy Excel电子表格行阅读器(类似于csvreader)。处理单元格内的回车。

在 Excel 电子表格中运行 JQuery 地理位置脚本

python 编写快速脚本,用于阅读我们的许多公司电子邮件,以获取Kidkraft的库存状态更新,然后下载附带的xlsx文件f

使用 ssis 脚本任务将查询结果附加为电子邮件中的 excel,而不存储 excel

以编程方式从 Excel 电子表格中提取数据

用于 Excel 电子表格的 Pandas groupby