绘制数据集以显示水平趋势——Python Pandas
水平趋势也称为平稳趋势。假设以下数据是我们数据集,即 SalesRecords3.csv
首先导入所需的库 −
import pandas as pd import matplotlib.pyplot as plt
将 CSV 文件中的数据加载到 Pandas DataFrame −
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords3.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\SalesRecords3.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()
输出
将生成如下输出 −
广告