我的数据集看起来像这样
Tr, Date, Time
AV81312,20161014,121000
AV81312,20161014,160221
AV85012,20170422,150858
AV85012,20161108,11137
AV86157,20170426,45747
AV86157,20170426,45744
AV86157,20160813,134312
我只需要从每个Tr具有最新记录的项目中选择一项,即日期和时间更高的最新记录
所需的输出是
Tr, Date, Time
AV81312,20161014,160221
AV85012,20170422,150858
AV86157,20170426,45747
我的代码是
df2 = read_csv("sample.csv")
df2 = df2.values
x = []
for i in df2:
for j in df2:
if i[2] == j[2]:
if i[3] >= j[3]:
x.append(i) 它没有按预期工作
相关分类