Question

Use Python

Step 1: Create a DataFrame of Aggregate Statistics Create a DataFrame ipCountDF that uses logDF to create a count of each tim

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As you are not given any where in the question what are the columns present in the logDf dataframe so i am assuming the logdf has a column ipaddress. which is more relevant to us now.

Code:

import pandas as pd
# create the empty ip address set to store unique ip address
ipadd = set()
# given data frame logDf get the unique ipaddress colums values
ipadd = set(logDf["ipaddress"])
# creating the list of all zeros initally to store count
count = [0 for i in ipadd]
# loop through each values in the logdf data frame ip address column and count th
# number of occurance
index=0
for j in ipadd:
   index = index+1
   for i in logDf["ipaddress"]:
       if i == j:
           count[index] = count[index]+1
       else:
           continue
# creating the dataframe ipCountDf with columns ip and count
# using ipadd set and count list
# create the dictonary initially
dct = {"ip":ipadd,"count":count}
ipCountDf = pd.DataFrame(dct)

# sorting the dataframe based on count in descending order
ipCountDf.sort_values(by="count",ascending=False,inplace=True)
# output the dataframe
print(ipCountDf)

Add a comment
Know the answer?
Add Answer to:
Use Python Step 1: Create a DataFrame of Aggregate Statistics Create a DataFrame ipCountDF that uses logDF to create a count of each time a given IP address appears in the logs, with the counts sorte...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT