Automatic creation of 2021 monthly calendar (refill for personal organizer) by Python

Purpose:

Creating a monthly calendar.

background:

I am using a personal organizer, but because the size of the refill (82mmW x 140mmL) is special, it is difficult to obtain, the price is reasonably high, and I thought about making it by hand in the past, but at that time I refilled I made a custom-made paper, and there was still blank paper left, so I thought about making it for the next year after a long absence. Since it is once a year, it can be handmade, but since there is a special programming environment, let's create a mechanism that can automatically output a calendar every year. That's why I tried programming.

printing:

Use the "mail merge" function of the word processing software. Therefore, calendar data for mail merge may be created. The template for "mail merge" is a template that is displayed for one month in a spread as shown in the figure below. calrendar_template.png

data:

One record is one month, so if you have a calendar database like the one shown below, you can use it for mail merge. This time, I tried to make this table with python. calrendar_db.png

The code is as follows

.ruby:monthly_calendar.py


import pandas as pd
import numpy as np
import calendar as cl
import os

"""
Completed version for the time being
"""

file='f.csv'
fout=open(file,'w',encoding="utf_8")

#Year to create
YEAR=2021

"""
Create data with while loop
m--> month
D--> date
out -->Collect data here
"""

m=1
out=""
while m < 13:
  MR=cl.monthrange(YEAR,m)
  out=("{0},".format(cl.month_name[m]))

  D=0
  while D < 37:
    while D < MR[0]:
      out+=("*,")
      D+=1
    if D < MR[1]+MR[0]:
      out+=("{0},".format(str(D-MR[0]+1)))
      D+=1
    else:
      out+=("*,")
      D+=1
  out=out[:-1]
  out='{0}\n'.format(out)
  print(out)
  fout.write(out)
  m+=1

fout.close()

body_df=pd.read_csv('f.csv',index_col=0,
                    names=['D0','D1','D2','D3','D4','D5','D6','D7','D8','D9','D10',
                           'D11','D12','D13','D14','D15','D16','D17','D18','D19','D20',
                           'D21','D22','D23','D24','D25','D26','D27','D28','D29','D30',
                           'D31','D32','D33','D34','D35' ,'D36'])
print(body_df)

body_df.to_csv('f_out.csv')
os.remove('f.csv')

There are some improvements and function additions such as "Month" at the beginning of the database index and manual input of holidays. I will start working when I feel like it.

Recommended Posts

Automatic creation of 2021 monthly calendar (refill for personal organizer) by Python
Pandas of the beginner, by the beginner, for the beginner [Python]
■ Kaggle Practice for Beginners --Introduction of Python --by Google Colaboratory
[For beginners] Basics of Python explained by Java Gold Part 1
Automatic update of Python module
Automatic acquisition of gene expression level data by python and R
[Let's play with Python] Aiming for automatic sentence generation ~ Completion of automatic sentence generation ~
Expansion by argument of python dictionary
Personal notes for python image processing
AWS Layer Creation Script for python
Behavior of python3 by Sakura's server
Introductory table of contents for python3
Record of Python introduction for newcomers
Story of power approximation by Python
Easy-to-understand explanation of Python Web application (Django) even for beginners (2) [Project creation]
Python learning memo for machine learning by Chainer until the end of Chapter 2