I use Pandas to store stock price data using data frames. There are 2940 rows in the data set. A snapshot is displayed below:

Time series data does not contain values for Saturday and Sunday. Therefore, the missing values must be filled.
Here is the code I wrote, but it does not solve the problem:
import pandas as pd
import numpy as np
import os
os.chdir('C:/Users/Admin/Analytics/stock-prices')
data = pd.read_csv('stock-data.csv')
data['PriceDate'] = pd.to_datetime(data['PriceDate'], format='%m/%d/%Y')
data = data.sort_index(by=['PriceDate'], ascending=[True])
idx = pd.date_range('08-25-2004',periods=2940,freq='D')
data = data.set_index(idx)
data['newdate']=data.index
newdate=data['newdate'].values
data = pd.merge(newdate, data, on='PriceDate', how='outer')
How to fill in the missing values on Saturday and Sunday?
source
share