绘制数据集以显示下降趋势 - Python Pandas
时间序列分析显示的下降模式就是我们所说的下降趋势。假设以下为我们的数据集,即 SalesRecords2.csv
首先,导入必要的库 −
import pandas as pd import matplotlib.pyplot as plt
从 CSV 文件加载数据到 Pandas DataFrame −
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords2.csv")
将列转换为日期时间对象 −
dataFrame['Sold_On'] = pd.to_datetime(dataFrame['Sold_On'])
为下降趋势创建绘图 −
dataFrame.plot()
示例
以下为代码 −
import pandas as pd import matplotlib.pyplot as plt # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords2.csv") print("Reading the CSV file...\n", dataFrame) # casting column to datetime object dataFrame['Sold_On'] = pd.to_datetime(dataFrame['Sold_On']) dataFrame = dataFrame.set_index('Sold_On') # Creating the plot dataFrame.plot() plt.show()
输出
这将生成以下输出 −
广告