1

I a have dataframe like this

CELL ID Party LOC Date & Time
10631 3009787 bwp 2021-10-01 8:20:30
10631 3009787 bwp 2021-10-01 8:40:50
50987 2275172 bwp 2021-10-02 7:50:20
50987 2275172 bwp 2021-10-02 7:23:16

I want output dataframe which contains grouped data .Use CELL ID, Party & Only Date Part of Date & time in group :

Output in this Format : https://i.sstatic.net/XFaDS.png

CELL ID -->Party --> Date & Time

2
  • 1
    Your Date & Time column currently only contains a date. What's the problem? Can you please provide a more representative sample dataframe? Commented Oct 8, 2021 at 16:28
  • groups should only contain date part of date & Time Commented Oct 8, 2021 at 16:31

1 Answer 1

1

Here you go:

# df["Date & Time"] = pd.to_datetime(df["Date & Time"])  # If not already datetime
df.set_index(["CELL ID", "Party", df["Date & Time"].dt.date])

Output:

                             LOC         Date & Time
CELL ID Party   Date & Time
10631   3009787 2021-10-01   bwp 2021-10-01 08:20:30
                2021-10-01   bwp 2021-10-01 08:40:50
50987   2275172 2021-10-02   bwp 2021-10-02 07:50:20
                2021-10-02   bwp 2021-10-02 07:23:16
Sign up to request clarification or add additional context in comments.

6 Comments

Now how can we combines these groups into a single dataframe
Wait, if that's what you want to do, then why not just remove the time values altogether, and the drop duplicates?
I want a dataframe that contains all these groups
You're going to need to provide your desired outcome because it's no longer clear what you're asking for.
@ZulqarnainSabir see my edit
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.