我们可以使用Python来解决这个问题。我们需要使用pandas和datetime模块。
首先,我们需要将日志文件加载到pandas DataFrame中:
import pandas as pd
df = pd.read_csv("access.log", sep="\s+", header=None, usecols=[0, 3], names=["ip", "time"])
这里我们假设日志文件中IP地址和时间戳之间使用空格分隔。
接下来,我们需要将时间戳转换为Python datetime对象。我们可以使用strptime函数来解析时间戳字符串并将其转换为datetime对象:
import datetime
df["time"] = df["time"].apply(lambda x: datetime.datetime.strptime(x, "[%d/%b/%Y:%H:%M:%S %z]"))
现在,我们可以使用resample函数按天和分钟将IP分组,并计算每个组中唯一IP的数量:
df.groupby([df["time"].dt.date, df["time"].dt.strftime("%H:%M")])["ip"].nunique()
这将返回一个Series对象,其索引为日期和分钟,值为唯一IP数。
上一篇:按天过滤pandas数据框
下一篇:按天和时间排序