在python中,给定开始日期:2018年11月2日(星期五), 我需要生成一个带有一系列每周日期的数据框,并将它们标记如下: 基本上每个日期对从一个星期五到下个星期四,跨度为1周
START_DT END_DT WEEK_IND MONTH_IND(same month as END_DT)
2018-11-01 2018-11-08 1 201811
2018-11-09 2018-11-15 2 201811
2018-11-16 2018-11-22 3 201811
2018-11-23 2018-11-29 4 201811
2018-11-30 2018-12-06 1 201812( WEEK_IND resets as it is a new month)
...
...
有人可以指出我正确的方向吗?
答案 0 :(得分:3)
您可以执行以下操作:
services.AddAuthentication
(
IISDefaults.AuthenticationScheme
).AddJwtBearer("Bearer", options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false,
ValidateIssuer = false,
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("someKey")),
ValidateLifetime = true,
};
}
);
输出
import pandas as pd
start = pd.date_range(start='20181102', end='20181231', freq='1w-FRI')
end = start + pd.DateOffset(6)
df = pd.DataFrame({ 'start': start, 'end': end, 'month': end.strftime('%Y%m')}, columns=['start', 'end', 'month'])
df['week'] = df.groupby('month').cumcount() + 1
print(df)
答案 1 :(得分:3)
echo (new \DateTime('2019-01-17T10:00:00-05:00'))->format('P');
输出
df = pd.DataFrame()
df['START_DT'] = pd.date_range(start='2018-11-02', freq = 'W-FRI', periods = 10)
df['END_DT'] = df['START_DT']+ pd.DateOffset(6)
df['MONTH_IND'] = df['END_DT'].dt.strftime('%Y%m')
df['WEEK_IND'] = df.groupby(by = 'MONTH_IND').cumcount()+1
答案 2 :(得分:2)
它具有Week
偏移量,用于生成接受工作日参数的每周数据,并导致生成的日期始终位于一周的特定日期-
from pandas.tseries.offsets import *
pd.to_datetime(df['START_DT']) + Week(weekday=3)
输出
0 2018-11-08
1 2018-11-15
2 2018-11-22
3 2018-11-29
4 2018-12-06