Home » how to calculation cost time [closed]

how to calculation cost time [closed]

Solutons:

I think I understand what you’re asking. You just want to have a new dataframe that calculates the time difference between the three different entries for each unique order id?

So, I start by creating the dataframe:

``````data = [
[11238,3943,201805030759165986,'新建订单',20180503075916,'2018/5/3 07:59:16','2018/5/3 07:59:16'],
[11239,3943,201805030759165986,'新建订单',20180503082115,'2018/5/3 08:21:15','2018/5/3 08:21:15'],
[11240,3943,201805030759165986,'新建订单',20180503083204,'2018/5/3 08:32:04','2018/5/3 08:32:04'],
[11241,3941,201805030856445991,'新建订单',20180503085644,'2018/5/3 08:56:02','2018/5/3 08:56:44'],
[11242,3941,201805022232081084,'初审成功',20180503085802,'2018/5/3 08:58:02','2018/5/3 08:58:02'],
[11243,3941,201805022232081084,'审核成功',20180503085821,'2018/5/3 08:59:21','2018/5/3 08:58:21']
]

df = pd.DataFrame(data, columns=['id','order_id','order_no','order_status','handle_time','create_time','update_time'])
df.loc[:, 'create_time'] = pd.to_datetime(df.loc[:, 'create_time'])
``````

Sort values by order_id and then create_time:

``````df = df.sort_values(by=['order_id', 'create_time'])
``````

Next, I group by order id and select the 1st, 2nd, and 3rd entry:

``````first_df = df.groupby('order_id').nth(0)
second_df = df.groupby('order_id').nth(1)
third_df = df.groupby('order_id').nth(2)
``````

Subtract the 1st from the second to get the 1st stage, and subtract the 2nd from the 3rd to get the second stage. Then combine them into an output dataframe:

``````stage_two = third_df.loc[:, 'create_time'] - second_df.loc[:, 'create_time']
stage_one = second_df.loc[:, 'create_time'] - first_df.loc[:, 'create_time']
stages = pd.concat([stage_one, stage_two], axis=1, keys=['stage_one', 'stage_two'])

print(stages)
``````

And the output looks like:

``````     stage_one stage_two
order_id
3941      00:02:00  00:01:19
3943      00:21:59  00:10:49
``````

Why would anyone choose not to use the lowlatency kernel?

The different configurations, “generic”, “lowlatency” (as configured in Ubuntu), and RT (“real-time”), are all about balancing throughput versus latency. Generic kernels favour throughput over latency, the others favour latency over throughput. Thus users who...

How can I update all Snap packages?

sudo snap refresh Will do this. It is part of snapd 2.0.8, which landed 2016-06-13 in xenial-updates. snap refresh --list Only lists the updates without refreshing the packages. snap info <snap name> Can show which versions are available for a particular...

What does Controls.Add() do in c#? [closed]

Controls is an instance of Control.ControlCollection class, which represents a collection of Control objects, Inheritance hierarchy is System.Windows.Forms.Control.ControlCollection Note: The Add, Remove, and RemoveAt methods enable you to add and remove...

Write an SQL query to find all those hostnames that have encountered multiple logs //“init failure” on any given day at 5 min interval

In SQL, you can use lag()/lead() to find such "adjacent" rows. Date functions are notoriously database dependent, but the idea is: select t.* from (select t.*, lead(time, 4) over (partition by hostname, date order by time) as time_4 from t where log = 'init...

How can I change the date modified/created of a file?

As long as you are the owner of the file (or root), you can change the modification time of a file using the touch command: touch filename By default this will set the file's modification time to the current time, but there are a number of flags, such as the -d...

How to read dmesg from previous session? (dmesg.0)

Although a bit late for the OP... I use Fedora, but if your system uses journalctl then you can easily get the kernel messages (dmesg log) from prior shutdown/crash (in a dmesg -T format) through the following. Options: -k (dmesg) -b < boot_number > (How...

Get data on daily basis in laravel

You can use the existing Laravel cron job scheduling to fulfill your specific requirement. Please refer following Laravels official documentation https://laravel.com/docs/5.8/scheduling#scheduling-queued-jobs I'll show a simple example to get an idea about this...

Get JavaScript object from array of objects by value of property [duplicate]

Filter array of objects, which property matches value, returns array: var result = jsObjects.filter(obj => { return obj.b === 6 }) See the MDN Docs on Array.prototype.filter() const jsObjects = [ {a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8} ] let...

Python speed testing – Time Difference – milliseconds

datetime.timedelta is just the difference between two datetimes ... so it's like a period of time, in days / seconds / microseconds >>> import datetime >>> a = datetime.datetime.now() >>> b = datetime.datetime.now() >>> c = b...

How to find the distance to the nearest coastline from Property Place latitude/longitude point?

One of the canonical tools for this is pdfinfo, which comes with xpdf, if I recall. Example output: [0 1017 17:10:17] ~/temp % pdfinfo test.pdf Creator: TeX Producer: pdfTeX-1.40.14 CreationDate: Sun May 18 09:53:06 2014 ModDate: Sun May 18 09:53:06 2014...

How can I search within the output buffer of a tmux shell?

copy mode search To search in the tmux history buffer for the current window, press Ctrl-b [ to enter copy mode. If you're using emacs key bindings (the default), press Ctrl-s then type the string to search for and press Enter. Press n to search for the same...

Often big numbers become negative

This image shows what you're looking for. In your case it's obviously larger numbers, but the principle stays the same. Examples of limits in java are: int: −2,147,483,648 to 2,147,483,647. long: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 In the...

Printing key value pair in Laravel blade using for each loop [closed]

Your code is a mess. here is a cleaner version without using the models (since you did not say if they are in place) Controller Code public function show_friend_request() { \$user_id = auth()->user()->id; \$senderIds =...

null pointer exception in java servlet [closed]

I got a "null pointer exception" fault in java servlet. Could someone tell me what happens? And how to avoid that? That happens when you're trying to access/invoke some reference which is actually null. SomeObject someObject = null; someObject.doSomething(); //...

How to set ulimits on service with systemd?

The mappings of systemd limits to ulimit Directive ulimit equivalent Unit LimitCPU= ulimit -t Seconds LimitFSIZE= ulimit -f Bytes LimitDATA= ulimit -d Bytes LimitSTACK= ulimit -s Bytes LimitCORE= ulimit -c Bytes LimitRSS= ulimit -m Bytes LimitNOFILE= ulimit -n...

Does compression option -z with rsync speed up backup

It's a general question. Does compression and decompression at endpoints improve the effective bandwidth of a link? The effective (perceived) bandwith of a link doing compression and decompression at endpoints is a function of: how fast you can compress (your...

How to pre-download items from a JSON list array in React JS?

You can insert <link rel="prefetch"> elements into the <head> of the page. This will tell the browser to go ahead and download the thing that it finds in the src property of that element so that it can be served from the cache if something else on...

C programming: Use of undeclared identifier [closed]

There are a lot of error in this program. In c programming, before using a variable, we must explicitly declare the type of data that it can store. So you must define the type of x and y to integer type (int x = 10,int y=12). The next thing is that you are...

How can I take an integer input from user and store it to an array? [closed]

My guess is that you have a letter case error in the real code. You define Number but print number, or vice versa. Names in Python are case sensitive. Or perhaps you have code in a function which tries to access number which was declared outside the function....