How to plot time series from 2 columns (Date and Value) by Python google colab?

91 views Asked by At

I'm newbie data sci and I try to make time series send to my teacher. She want the time series with 1 column data and prediction.

I tried to search about this in my language (Thai). But no one teaches about time series by python in Thai language.

I don't know how to... please help me

Sample Data Picture Here enter image description here

Dataset https://drive.google.com/file/d/1WpOFLtS1VXPA13Q2ofTTvQhRB2ZpebjY/view?usp=sharing

I need a code or guide me

1

There are 1 answers

0
D.L On

for the data that you have provide I can save the CSV file (to my windows downloads folder) and do this relatively quickly out of the box:

import pandas as pd
import matplotlib.pyplot as plt

file = "C:\\Users\\admin\\Downloads\\PM2dot5.csv"
df = pd.read_csv(file)



# Create plot
fig, ax = plt.subplots()
ax.plot(df['Date'], df['18T'], label='original data')

window_size = 10
df['Moving Avg'] = df['18T'].rolling(window=window_size).mean() 
ax.plot(df['Date'], df['Moving Avg'], label='moving avg')

# Add labels and title
ax.set_xlabel('date')
ax.set_ylabel('18T')
ax.set_title('time series') 

# Display plot
plt.show()

The above produces this chart: enter image description here

From this point you would need to elaborate on what you want in terms of prediction, perhaps a moving average which is relatively easy to achieve, so i have thrown this in for free...