pandas - Translating Zip, OrderedDict and DataFrame from Python to Typescript -
i have following code in python:
import pandas pd import numpy 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() 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 i, key in enumerate(weekdays, 1): if startday < 1 or startday > 7: error_flag = 1 break elif < 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) key, j in zip(weekdays.keys(), range(j, days_in_month)): month_df.set_value(1, key, j + 1) key, j in zip(weekdays.keys(), range(j + 1, days_in_month)): month_df.set_value(2, key, j + 1) key, j in zip(weekdays.keys(), range(j + 1, days_in_month)): month_df.set_value(3, key, j + 1) key, j in zip(weekdays.keys(), range(j + 1, days_in_month)): month_df.set_value(4, key, j + 1) 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)
i need translate typescript. don't want people me in entirety, thought best include whole python code completeness.
so best ways reproduce behaviour of ordereddict in typescript??
how if want reproduce behaviour of zip?
what dataframes? structure should use?
here ts far. thin coz stumped start - heroes creates array of html objects in html file, , array output to:
import { component, oninit } '@angular/core'; @component({ selector: 'app-events', templateurl: './events.component.html', styleurls: ['./events.component.css'] }) export class eventscomponent implements oninit { weekdays: []; monthslist: []; startday: number; month: number; heroes: []; 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; } }
Comments
Post a Comment