Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
grouped data frame
#1
Hi everyone,
I would like to group the dataframe using multiple keys. I used a data frame like (test_df) below:

dstIP srcIP attack_type port datetime
0 92.57.32.115 183.134.75.216 BruteForce 22 1604339526
1 92.57.32.115 112.85.42.121 SCAN 22 1604339522
2 92.57.32.115 112.85.42.121 BruteForce 22 1604339522
3 92.57.32.115 112.85.42.121 BruteForce 22 1604339521
4 92.57.32.115 76.102.78.161 BruteForce 22 1604339517

To aggregate rows with same dstIP, srcIP , attack_type and port, I grouped them with multiple keys and use maximum datatime as follows:

grouped = test_df.groupby(['srcIP', 'dstIP', 'attack_type','port']).aggregate({'datetime':'max'})

However, I do not know how to access each value in grouped for example I want to know the datatime for srcIP= 112.85.42.121 in grouped dataframe but I receive error when I use the following command:
Value_Target = grouped.loc[grouped['srcIP']==' 112.85.42.121 ']['datetime'].values
Also, I would like to print first value of dataframe in source IP column and I cannot use : grouped["srcIP"][0]
I will be thankful to know how I can solve my issues.
Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping in pandas/multi-index data frame Aleqsie 3 669 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Filtering Data Frame, with another value NewBiee 9 1,399 Aug-21-2023, 10:53 AM
Last Post: NewBiee
  Exporting data frame to excel dyerlee91 0 1,631 Oct-05-2021, 11:34 AM
Last Post: dyerlee91
  Pandas Data frame column condition check based on length of the value aditi06 1 2,697 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Adding a new column to a Panda Data Frame rsherry8 2 2,123 Jun-06-2021, 06:49 PM
Last Post: jefsummers
  how to filter data frame dynamically with the columns psahay 0 2,405 Aug-24-2020, 01:10 PM
Last Post: psahay
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 2,222 Aug-03-2020, 02:05 AM
Last Post: scidam
  How to shift data frame rows of specified column Mekala 0 1,903 Jul-21-2020, 02:42 PM
Last Post: Mekala
  HELP- DATA FRAME INTO TIME SERIES- BASIC bntayfur 0 1,759 Jul-11-2020, 09:04 PM
Last Post: bntayfur
  Pandas data frame creation from Kafka Topic vboppa 0 1,942 Jul-01-2020, 04:23 PM
Last Post: vboppa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020