how to choose random datetime of two different columns?
up vote
1
down vote
favorite
After some merging data, I have got a dataframe
as:
Name Stage Start End
Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15
so I need to arrange these data as follows, in form like start
of A1
and end
of A4
:
Name Stage Start End
Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15
How this could be acheived ? I am quite new with python
and pandas
.
python-2.7 pandas dataframe slice
add a comment |
up vote
1
down vote
favorite
After some merging data, I have got a dataframe
as:
Name Stage Start End
Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15
so I need to arrange these data as follows, in form like start
of A1
and end
of A4
:
Name Stage Start End
Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15
How this could be acheived ? I am quite new with python
and pandas
.
python-2.7 pandas dataframe slice
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
After some merging data, I have got a dataframe
as:
Name Stage Start End
Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15
so I need to arrange these data as follows, in form like start
of A1
and end
of A4
:
Name Stage Start End
Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15
How this could be acheived ? I am quite new with python
and pandas
.
python-2.7 pandas dataframe slice
After some merging data, I have got a dataframe
as:
Name Stage Start End
Hulk A1 21/10/2018 06:34:15 21/10/2018 07:34:15
Hulk A4 21/10/2018 07:34:15 21/10/2018 08:34:15
Sam A1 21/10/2018 09:34:15 21/10/2018 10:34:15
Sam A4 21/10/2018 10:34:15 21/10/2018 11:34:15
so I need to arrange these data as follows, in form like start
of A1
and end
of A4
:
Name Stage Start End
Hulk A1,A4 21/10/2018 06:34:15 21/10/2018 08:34:15
Sam A1,A4 21/10/2018 09:34:15 21/10/2018 11:34:15
How this could be acheived ? I am quite new with python
and pandas
.
python-2.7 pandas dataframe slice
python-2.7 pandas dataframe slice
edited Nov 10 at 12:14
James Z
11.1k71735
11.1k71735
asked Nov 10 at 11:03
Ranjan raghav
153
153
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Use agg
what working with first
and last
function nice, if for each group are 2 Stage values ordered like in sample data:
Also join
is pure python function.
df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
print (df)
Name Stage Start End
0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15
1
thanks for the solution. But in doc ofagg
underpandas
there is no info aboutjoin
,first
,last
...How do one learn about it ? @jezrael
– Ranjan raghav
Nov 10 at 11:15
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Use agg
what working with first
and last
function nice, if for each group are 2 Stage values ordered like in sample data:
Also join
is pure python function.
df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
print (df)
Name Stage Start End
0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15
1
thanks for the solution. But in doc ofagg
underpandas
there is no info aboutjoin
,first
,last
...How do one learn about it ? @jezrael
– Ranjan raghav
Nov 10 at 11:15
add a comment |
up vote
1
down vote
accepted
Use agg
what working with first
and last
function nice, if for each group are 2 Stage values ordered like in sample data:
Also join
is pure python function.
df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
print (df)
Name Stage Start End
0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15
1
thanks for the solution. But in doc ofagg
underpandas
there is no info aboutjoin
,first
,last
...How do one learn about it ? @jezrael
– Ranjan raghav
Nov 10 at 11:15
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Use agg
what working with first
and last
function nice, if for each group are 2 Stage values ordered like in sample data:
Also join
is pure python function.
df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
print (df)
Name Stage Start End
0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15
Use agg
what working with first
and last
function nice, if for each group are 2 Stage values ordered like in sample data:
Also join
is pure python function.
df = df.groupby('Name', as_index=False).agg('Stage':', '.join,'Start':'first', 'End':'last')
print (df)
Name Stage Start End
0 Hulk A1, A4 21/10/2018 06:34:15 21/10/2018 08:34:15
1 Sam A1, A4 21/10/2018 09:34:15 21/10/2018 11:34:15
edited Nov 10 at 11:17
answered Nov 10 at 11:10
jezrael
313k21250327
313k21250327
1
thanks for the solution. But in doc ofagg
underpandas
there is no info aboutjoin
,first
,last
...How do one learn about it ? @jezrael
– Ranjan raghav
Nov 10 at 11:15
add a comment |
1
thanks for the solution. But in doc ofagg
underpandas
there is no info aboutjoin
,first
,last
...How do one learn about it ? @jezrael
– Ranjan raghav
Nov 10 at 11:15
1
1
thanks for the solution. But in doc of
agg
under pandas
there is no info about join
, first
, last
...How do one learn about it ? @jezrael– Ranjan raghav
Nov 10 at 11:15
thanks for the solution. But in doc of
agg
under pandas
there is no info about join
, first
, last
...How do one learn about it ? @jezrael– Ranjan raghav
Nov 10 at 11:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238294%2fhow-to-choose-random-datetime-of-two-different-columns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown