How to add 'Timedelta' values in a python list - list

I am trying to calculate the average of some time duration which I got from timestamp values .
So,I have a list having timedelta values and I want to add it and then calculate the average.
But, when I try to add it python gives me error as:
ValueError: cannot construct a TimeDelta without a value/unit or descriptive keywords (days,seconds....)
Here is the list I have:
[Timedelta('0 days 00:02:52'), Timedelta('0 days 00:02:11'), Timedelta('0 days 00:02:16'),
Timedelta('0 days 00:02:58'), Timedelta('0 days 00:02:01'), Timedelta('0 days 00:02:13'),
Timedelta('0 days 00:02:50'), Timedelta('0 days 00:02:00'), Timedelta('0 days 00:02:09'),
Timedelta('0 days 00:02:04'), Timedelta('0 days 00:02:46'), Timedelta('201 days 00:12:05'),
Timedelta('0 days 00:02:08'), Timedelta('0 days 00:02:47'), Timedelta('0 days 00:02:01'),
Timedelta('0 days 00:02:46'), Timedelta('0 days 00:02:46'), Timedelta('0 days 00:02:15'),
Timedelta('0 days 00:02:03'), Timedelta('0 days 00:02:04'), Timedelta('0 days 00:02:04'),
Timedelta('0 days 00:02:47'), Timedelta('0 days 00:02:17'), Timedelta('0 days 00:03:00'),
Timedelta('0 days 00:03:03'), Timedelta('0 days 00:01:53')]
Could anyone please help me to understand what I am missing ?
Really appreciate your help.
Thank you!

Related

PowerBI: Calculating Margin net of Labour

I am new to Powerbi and needed some help on creating a dax calculation.
Objective: calculate the margin net of labour costs.
I already have a table that contains the margin$(price - cost).
Regarding labour info:
the fixed wage rate is $17.00
During the week the number of hours worked is 9/ per weekday
on saturday the number of hours worked is 8
on sunday the number of hours worked is 6
I want to create a function that tells me the labour cost for a given day and overall labour cost should sum as each day passes.
I figured I should create specific variables in DAX but following that is were I am confused.
How do I dictate to powerbi the hours and rate to apply? any guidance?
|rate:17.00|
|weekdayhours: 9|
|sathours: 8|
|sunhours: 6|

How to calculate number of hours when hours per day changed during the course of the project in Python 2.7 Django-admin

For example, I have to input hours per day and yesterday it was 4.0 then I want to change it to 6.0 today. How can I calculate the total number of hours, retaining the previous hours and adding it to the new hours, in a given date range?

Leave calculation mistake odoo

Hi i want to calculate half day leave for an employee. when applying for leave, the duration is set as 1/05/2018 18:30 -1/05/2018 23:30. ie 1.00pm to 6.00pm (ist).the day's calculation shows as 0.5 days. Working hour is scheduled as 9.00-18.00. But when generating payslip for the same employee total working days is shown as 31 days and working hours as 279. Odoo does not calculate the half day leave. how can i fix this? i have a doubt about specifying the time in duration while applying for leave. is it should be converted to utc?

If 'timesince' is over 24 hours then just display the day count and not the hours count

If a question posted is over 24 hours old then I want to limit it to show the day count and not the hours count. Obviously if under 24 hours old then show the hours count.
Currently: Asked 1 day, 18 hours ago
Optimal: Asked 1 day ago
{{question.created|timesince}}
Still fairly new to Django, any help would be appreciated.
Have a look at naturaltime: https://docs.djangoproject.com/en/dev/ref/contrib/humanize/#naturaltime
It should give you what you're looking for.

Finding the day of the thirteenth of every month over a period of years

I am currently trying to solve some problems from the USACO training website in preparation for an unrelated C++ programming competition.
However, I am stuck on this problem:
Does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is non-negative and will not exceed 400.
The number N is provided in an input file and the output is to be a file with seven numbers in it, each representing the number of 13th's falling on a particular day of the week.
I was wondering how you guys would approach this problem. I am not looking for code or anything since that would just defeat the purpose of me doing this, instead just a starting point or an algorithm would be helpful.
So far the only thing I could think of is using the Doomsday Algorithm, however I am unsure about how I would implement that in code.
Any help would be greatly appreciated.
As Denny says, N is so small that you can easily iterate through the months using a table of days-in-a-month and a simple is-a-leap-year predicate to handle February. Just find out what day the 13th of Jan was in 1900 and then add up the elapsed days until 13th Feb, then 13th March etc.. Use a % operator to wrap the # of elapsed days back into a day-of-week value.
N is less than 400? well you just need to go over 365.25*400=146100 days at max. sounds easy to enumerate all of them, convert dates into year/month/date (with your favorite date conversion routine), testing for day of week is trivial.
I would precalculate the table though.
Just use brute force. Like this pseudocode example:
from datetime import date
day_names = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday']
counts = [0] * 7
for year in range(1900, 2300):
for month in range(1, 13):
counts[date(year, month, 13).weekday()] += 1
for day, count in zip(day_names, counts):
print('%s: %d' % (day, count))
The "hard" part is calculating the day of the week a date falls on. In C(++), you can use the mktime and localtime library functions if you know that your platform handles a large enough date range.