Suk*_*djf 3 python date dataframe pandas pandasql
我有三个变量
csiti - 23454 : (整数)
单位 - [ 11,22,33,44,55,66,77] : (整数列表,总是特定长度 'n' )
begin_date - '2019-10-16' :(字符串)
我如何从这些数据创建一个数据框,比如
csiti units forecast_date
1928422 11 2019-10-16
1928422 22 2019-10-17
1928422 33 2019-10-18
1928422 44 2019-10-19
1928422 55 2019-10-20
1928422 66 2019-10-21
1928422 77 2019-10-22
Run Code Online (Sandbox Code Playgroud)
该forecast_date
列应该是从begin_date
值开始的未来日期。
使用DataFrame
构造函数 with date_range
for datetime with period 参数按列表中的值的长度units
:
csiti = 23454
units = [11,22,33,44,55,66,77]
begin_date = '2019-10-16'
df = pd.DataFrame({'csiti':csiti,
'units':units,
'forecast_date':pd.date_range(begin_date, periods=len(units))})
print (df.head(10))
csiti units forecast_date
0 23454 11 2019-10-16
1 23454 22 2019-10-17
2 23454 33 2019-10-18
3 23454 44 2019-10-19
4 23454 55 2019-10-20
5 23454 66 2019-10-21
6 23454 77 2019-10-22
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5749 次 |
最近记录: |