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
New contributor
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
New contributor
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
New contributor
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
New contributor
New contributor
edited 2 days ago
James Z
11.1k71735
11.1k71735
New contributor
asked 2 days ago
Ranjan raghav
153
153
New contributor
New contributor
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
2 days ago
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
2 days ago
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
2 days ago
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 2 days ago
answered 2 days ago
jezrael
305k20238314
305k20238314
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
2 days ago
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
2 days ago
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
2 days ago
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
2 days ago
add a comment |
Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.
Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.
Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.
Ranjan raghav is a new contributor. Be nice, and check out our Code of Conduct.
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
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
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
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
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