Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

พลอตข้อมูลแสดง Downtrend ด้วย Python Pandas

บทนำ

Downtrend คือแนวโน้มลงของ Time Series ใช้ข้อมูล SalesRecords2.csv

ขั้นตอน

  1. นำเข้า pandas, matplotlib
  2. โหลด CSV แปลง Sold_On เป็น datetime ตั้งเป็น Index
  3. พลอตด้วย dataFrame.plot()

โค้ดเต็ม

import pandas as pd
import matplotlib.pyplot as plt

dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesRecords2.csv")
print("Reading the CSV file...\n", dataFrame)

dataFrame['Sold_On'] = pd.to_datetime(dataFrame['Sold_On'])
dataFrame = dataFrame.set_index('Sold_On')

dataFrame.plot()
plt.show()

ผลลัพธ์

ได้กราฟแสดงแนวโน้มลง (Downtrend) ของข้อมูลขายตามเวลา