提前感謝您的反饋!我正在處理時間序列資料,其中有 2 列索引轉換為 DateTime 物件。我正在處理的內容如下所示:

我正在嘗試決議每家商店的銷售記錄,以便我可以為每家商店定制銷售預測。有什么建議嗎?
非常感謝!
uj5u.com熱心網友回復:
您可以僅按'Store'列查詢/切片資料框,也可以執行.groupby('Store').,或將索引設定為['Store', 'Fiscal_Date']. 不是很清楚你想做什么。也許這有幫助?
import pandas as pd
df = pd.DataFrame({'Fiscal_Date':['2013-12-01','2013-12-01','2013-12-02','2013-12-02'],
'Store':['A','B','A','B'],
'Sale':[12,143,23,21]})
df = df.set_index(['Fiscal_Date']).sort_index()
for store in list(df['Store'].unique()):
filter_df = df[df['Store'] == store]
print(filter_df)
輸出:
Store Sale
Fiscal_Date
2013-12-01 A 12
2013-12-02 A 23
Store Sale
Fiscal_Date
2013-12-01 B 143
2013-12-02 B 21
uj5u.com熱心網友回復:
df = 資料框名稱
要獲取特定商店的銷售價值:
df["Sale"].loc[(df["Store"] == "StoreName")]
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/344588.html
上一篇:按索引減去兩個資料幀并保留字串列
下一篇:在Pandas中按日期排序
