I wrote it while studying to draw a graph using Python for the first time.
This time, we will display the daily average temperature and precipitation data of Tottori City in a graph. Obtain data from Japan Meteorological Agency | Download past weather data Parse the following csv file.
time, temperature,precipitation
2019/8/5,30.2,0
2019/8/6,30.1,0
2019/8/7,31.6,0
2019/8/8,31,0
2019/8/9,29.6,0
2019/8/10,29.8,0
2019/8/11,30.3,0
…
The following files worked with Python 3.7.
from matplotlib import pyplot as plt
import pandas as pd
#CSV file pandas.Read as DataFrame
# index(Heading column)Specify the time column as
#Header by default=0 is specified and the first line is ignored as a header
data = pd.read_csv(r'data.csv', index_col='time')
#Row and column extraction
# :Is the whole line,'[0,1]'Extracts 2 columns except the column specified as index
df = data.iloc[:, [0,1]]
#Plot the data
df.plot()
#Graph title
plt.title("tottori")
#Show graph
plt.show()
[How to read a csv file using Python / pandas / matplotlib and draw a nice graph (Mac / Raspberry Pi) --karaage. [Karaage]](https://karaage.hatenadiary.jp/entry/2017/05/ 25/073000) Read csv / tsv file with pandas (read_csv, read_table) | note.nkmk.me