process:
- set index of the date
- resample the dataframe with 'D'
- drop the day is Sat and Sun
- fillna with 'ffill'
# Data Index should be timeSeries
df['Date'] = pd.to_datetime(df['Date'], format='%d-%m-%Y')
# upsample
dfn = df.set_index('Date').resample('D').asfreq()
# covert Date to Monday .. Sunday
dfn['Day'] = dfn.index.strftime('%A')
# drop Day in ['Saturday', 'Sunday']
cond = dfn['Day'].isin(['Saturday', 'Sunday'])
dfn = dfn[~cond].fillna(method='ffill').reset_index()
output:
Date Day Open High Low Close Adjusted Close
0 2007-09-17 Monday 6898.00 6977.20 6843.00 6897.10 6897.100098
1 2007-09-18 Tuesday 6921.15 7078.95 6883.60 7059.65 7059.649902
2 2007-09-19 Wednesday 7111.00 7419.35 7111.00 7401.85 7401.850098
3 2007-09-20 Thursday 7404.95 7462.90 7343.60 7390.15 7390.149902
4 2007-09-21 Friday 7378.30 7506.35 7367.15 7464.50 7464.500000
5 2007-09-24 Monday 7378.30 7506.35 7367.15 7464.50 7464.500000
6 2007-09-25 Tuesday 7658.50 7694.25 7490.20 7629.15 7629.149902
7 2007-09-26 Wednesday 7647.10 7829.85 7591.80 7755.90 7755.899902
8 2007-09-27 Thursday 7647.10 7829.85 7591.80 7755.90 7755.899902
9 2007-09-28 Friday 7838.25 8082.85 7836.05 8042.20 8042.200195
10 2007-10-01 Monday 8008.55 8085.15 7913.30 7987.50 7987.500000
11 2007-10-02 Tuesday 8008.55 8085.15 7913.30 7987.50 7987.500000
12 2007-10-03 Wednesday 8029.80 8235.80 7820.25 8097.90 8097.899902
13 2007-10-04 Thursday 8083.30 8086.70 7828.65 8035.90 8035.899902
14 2007-10-05 Friday 8038.10 8066.55 7789.70 7845.25 7845.250000
15 2007-10-08 Monday 7853.15 7935.45 7516.45 7626.40 7626.399902
16 2007-10-09 Tuesday 7580.90 7916.45 7535.05 7895.85 7895.850098
17 2007-10-10 Wednesday 7960.65 8081.05 7907.35 8030.65 8030.649902
18 2007-10-11 Thursday 8054.30 8177.75 8005.50 8158.80 8158.799805
19 2007-10-12 Friday 8054.30 8177.75 8005.50 8158.80 8158.799805
20 2007-10-15 Monday 7962.55 8306.35 7962.55 8286.30 8286.299805
21 2007-10-16 Tuesday 8361.40 8491.65 8240.30 8452.20 8452.200195
22 2007-10-17 Wednesday 8071.55 8218.10 7641.50 8099.90 8099.899902
23 2007-10-18 Thursday 8055.15 8192.45 7519.70 7608.75 7608.750000
24 2007-10-19 Friday 7637.40 7718.90 7279.30 7423.80 7423.799805
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…