绘制数据集以显示上升趋势 – Python Pandas
时间序列分析显示的上升模式就是我们所说的上升趋势。假设以下是我们的数据集,即SalesRecords.csv
首先,导入所需的库 -
import pandas as pdimportmatplotlib.pyplotas plt
将 CSV 文件中的数据加载到 Pandas DataFrame 中 -
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesRecords.csv")
将列转换为日期时间对象 -
dataFrame['Date_of_Purchase'] = pd.to_datetime(dataFrame['Date_of_Purchase'])
创建上升趋势图 -
dataFrame.plot()
示例
以下是代码 -
import pandas as pd输出结果importmatplotlib.pyplotas plt
# Load data from a CSV file into a Pandas DataFrame
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\SalesRecords.csv")
print("Reading the CSV file...\n", dataFrame)
# casting column to datetime object
dataFrame['Date_of_Purchase'] = pd.to_datetime(dataFrame['Date_of_Purchase'])
dataFrame = dataFrame.set_index('Date_of_Purchase')
# Creating the plot
dataFrame.plot()
plt.show()
以下是输出 -
以上是 绘制数据集以显示上升趋势 – Python Pandas 的全部内容, 来源链接: utcz.com/z/363204.html