[Python] Plot time series data

How the objective variable changes when analyzing time series data Visualize as a graph for checking in chronological order.

procedure ** ① Index the date column **  df.set_index('Date') ** ② Plot **  df.plot()  plt.xticks(rotation=70) ** ③ Undo for later processing **  df = df.reset_index()

date.py


import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('dataset.csv')
df.head()

"""output
	patient	Last UpDdated	
0	5.0	    2020-03-22 10:00:00
1	4.0	    2020-03-22 11:00:00
2	6.0	    2020-03-22 12:00:00
3	10.0	2020-03-23 10:00:00	
4	3.0	    2020-03-23 11:00:00
"""

#Index the date
df = df.set_index('Last UpDdated')
df.head(3)

"""output

Last UpDdated     patient	
2020-03-22 10:00:00	 5.0
2020-03-22 11:00:00	 4.0
2020-03-22 12:00:00	 6.0
"""

#plot
df.plot()
#Change the angle of the X-axis label
plt.xticks(rotation=70)

ダウンロード (1).png

date.py


#Return the index for later processing
df = df.reset_index()
df.head(3)

"""output
    Last UpDdated	    patient
0	2020-03-22 10:00:00	5.0
1	2020-03-22 11:00:00	4.0
2	2020-03-22 12:00:00	6.0
"""

Recommended Posts

[Python] Plot time series data
Python: Time Series Analysis: Preprocessing Time Series Data
Time series plot started ~ python edition ~
Time series plot / Matplotlib
Get time series data from k-db.com in Python
Plot CSV of time series data with unixtime value in Python (matplotlib)
About time series data and overfitting
Differentiation of time series data (discrete)
Time series analysis 3 Preprocessing of time series data
Graph time series data in Python using pandas and matplotlib
Forecasting time series data with Simplex Projection
First time python
[Python] Violin Plot
Predict time series data with neural network
Data analysis python
python time measurement
[Python] Accelerates loading of time series CSV
First time python
Time series data anomaly detection for beginners
How to handle time series data (implementation)
Reading OpenFOAM time series data and sets data
[python] Read data
Python: Time Series Analysis: Building a SARIMA Model
Python: Time Series Analysis: Stationarity, ARMA / ARIMA Model
Kaggle Kernel Method Summary [Table Time Series Data]
Acquisition of time series data (daily) of stock prices
[Python] Conversion memo between time data and numerical data
Smoothing of time series and waveform data 3 methods (smoothing)
How to read time series data in PyTorch
Format and display time series data with different scales and units with Python or Matplotlib
Data analysis with python 2
Function execution time (Python)
Python Data Visualization Libraries
Data analysis overview python
Data cleaning using Python
RNN_LSTM1 Time series analysis
Output python execution time
Time floor function (Python)
Python data analysis template
[Python tutorial] Data structure
[Python] Sorting Numpy data
python get current time
Python Mathematics Series ① Transpose
Data analysis with Python
Display TOPIX time series
Features that can be extracted from time series data
Python 3.4 Create Windows7-64bit environment (for financial time series analysis)
Anomaly detection of time series data by LSTM (Keras)
Time series data prediction by AutoML (automatic machine learning)
[Time series with plotly] Dynamic visualization with plotly [python, stock price]
Reading, summarizing, visualizing, and exporting time series data to an Excel file with Python
Implementation of clustering k-shape method for time series data [Unsupervised learning with python Chapter 13]
"Getting stock price time series data from k-db.com with Python" Program environment creation memo
Predict from various data in Python using Facebook Prophet, a time series prediction tool
Python Math Series ② Matrix Multiplication
Sample data created with python
My python data analysis container
Handle Ambient data in Python
data structure python push pop
Python application: Pandas Part 2: Series
Python 2 series and 3 series (Anaconda edition)