我在Python中有以下代码:
import pandas as pd
import numpy as np
import collections
import copy
weekdays = { 1 : 'Null', 2 : 'Null', 3 : 'Null', 4 : 'Null', 5 : 'Null', 6 : 'Null', 7 : 'Null'}
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
days_in_month_in_year = {'2017' : [31, 28, 31, 30, 31, 30, 31, 31, 30, 30, 30, 31], '2018' : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], '2019' : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],'2020' : [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] }
days_in_month_in_year = pd.DataFrame(days_in_month_in_year, index=months)
startday = 7
month = 0
dict_of_months = collections.OrderedDict()
for index, row in days_in_month_in_year.iterrows():
month_name = months[month]
print (month_name)
days_in_month = (row['2019'])
month_df = pd.DataFrame({}, columns=[1, 2, 3, 4, 5, 6, 7])
error_flag = 0
for i, key in enumerate(weekdays, 1):
if startday < 1 or startday > 7:
error_flag = 1
break
elif i < startday:
weekdays[key] = "Null"
month_df.set_value(0, i, "Null")
else:
j = (i - startday) + 1
weekdays[key] = j
month_df.set_value(0, i, j)
for key, j in zip(weekdays.keys(), range(j, days_in_month)):
month_df.set_value(1, key, j + 1)
for key, j in zip(weekdays.keys(), range(j + 1, days_in_month)):
month_df.set_value(2, key, j + 1)
for key, j in zip(weekdays.keys(), range(j + 1, days_in_month)):
month_df.set_value(3, key, j + 1)
for key, j in zip(weekdays.keys(), range(j + 1, days_in_month)):
month_df.set_value(4, key, j + 1)
for key, j in zip(weekdays.keys(), range(j + 1, days_in_month)):
month_df.set_value(5, key, j + 1)
month_df = month_df.fillna("Null")
if len(month_df.index) < 6:
null_row = pd.Series(['Null', 'Null', 'Null', 'Null', 'Null', 'Null', 'Null'], [1,2,3,4,5,6,7])
month_df = month_df.append([null_row], ignore_index=True)
startday = startday + ( days_in_month % 7 )
if startday > 7:
startday = startday - 7
print (month_df)
print (startday)
month = month + 1
dict_of_months[month_name] = month_df
print (dict_of_months)
我需要将其翻译为Typescript。我不希望人们为我完整地做这件事,但我认为最好包括我的整个Python代码以保证完整性。
那么在Typescript中重现OrderedDict行为的最佳方法是什么?
如果我想重现zip的行为怎么样?
数据帧怎么样?我应该使用什么结构?
到目前为止,这是我的。这是非常薄的因为我难倒在哪里开始 - 英雄在html文件中创建一个html对象数组,并将是我最终输出到的数组:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-events',
templateUrl: './events.component.html',
styleUrls: ['./events.component.css']
})
export class EventsComponent implements OnInit {
weekdays: any [];
monthslist: any [];
startday: number;
month: number;
heroes: any [];
ngOnInit() {
this.heroes = [
{ name: '' },
{ name: '' },
{ name: '' },
{ name: '' },
{ name: '' },
{ name: '' },
{ name: '' },
{ name: '' },
{ name: '' }
];
this.weekdays = ['Null', 'Null', 'Null', 'Null', 'Null', 'Null', 'Null'];
this.monthslist = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
this.startday = 7;
this.month = 0;
}
}