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)
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...