[PYTHON] Make holiday data into a data frame with pandas

TL;DR

from io import StringIO
import urllib.request

import pandas as pd

req = urllib.request.Request('https://holidays-jp.github.io/api/v1/date.csv')
with urllib.request.urlopen(req) as res:
    df_holiday = pd.read_csv(StringIO(res.read().decode()), header=None)

Code commentary

Throw a get request to a location where you can get holiday data

req = urllib.request.Request('https://holidays-jp.github.io/api/v1/date.csv')

Simple Izu Vest

Extract data from get request

with urllib.request.urlopen(req) as res:
    df_holiday = pd.read_csv(StringIO(res.read().decode()), header=None)

Since the request data is binary data, it is converted to string by the decode function, and the input is sent to the read_csv function using StringIO.

Summary

This method is for making it simple. If you want more detailed holiday data, you may be happy with the jpholiday library.

Reference article

--Urllib.request is sufficient for Python HTTP client

Recommended Posts

Make holiday data into a data frame with pandas
Make multiple numerical elevation data into a single picture with Python
Data visualization with pandas
Data manipulation with Pandas!
I want to give a group_id to a pandas data frame
Make a CSV formatting tool with Python Pandas PyInstaller
Data processing tips with Pandas
Make a fire with kdeplot
I tried scraping food recall information with Python to create a pandas data frame
Ingenuity to handle data with Pandas in a memory-saving manner
A collection of methods used when aggregating data with pandas
Make a sound with Jupyter notebook
Let's make a breakout with wxPython
Versatile data plotting with pandas + matplotlib
Make a recommender system with python
Draw a graph with pandas + XlsxWriter
Make a filter with a django template
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a model iterator with PySide
Make a nice graph with plotly
Data accumulation with GCP's permanent free frame
Let's make a shiritori game with Python
Make a video player with PySimpleGUI + OpenCV
Add a Python data source with Redash
Make a Notebook Pipeline with Kedro + Papermill
Make a partially zoomed figure with matplotlib
Make a drawing quiz with kivy + PyTorch
Let's make a voice slowly with Python
Divide data into project-like units with Django (2)
Make a cascade classifier with google colaboratory
Let's make a simple language with PLY 1
Try converting to tidy data with pandas
Make a logic circuit with a perceptron (multilayer perceptron)
Make a Yes No Popup with Kivy
Make a wash-drying timer with a Raspberry Pi
Make a GIF animation with folder monitoring
[BigQuery] Load a part of BQ data into pandas at high speed
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Read a character data file with numpy
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Make a decision tree from 0 with Python and understand it (4. Data structure)
Working with 3D data structures in pandas
Let's make a web framework with Python! (2)
Example of efficient data processing with PANDAS
Best practices for messing with data with pandas
Convert Mobile Suica usage history PDF to pandas Data Frame format with tabula-py
Format DataFrame data with Pytorch into a form that can be trained with NN
Change the data frame of pandas purchase data (id x product) to a dictionary
A memorandum of method often used when analyzing data with pandas (for beginners)
Create a frame with transparent background with tkinter [Python]
Make Python scripts into Windows-executable .exes with Pyinstaller
Try to aggregate doujin music data with pandas
Investment quest: Make a system trade with pyhton (2)
Make a Twitter trend bot with heroku + Python
[Python] Make a game with Pyxel-Use an editor-
Make a monitoring device with an infrared sensor
Read Python csv data with Pandas ⇒ Graph with Matplotlib
Delete data in a pattern with Redis Cluster