你可以通过这个sn-p实现这个:
import numpy
datas = numpy.array([
# channelId, videoId, userId, date, popularity, comment
[0, 0, 1, "02052021", 3044, "blobi"],
[1, 2, 1, "01052021", 4234, "uygukih"],
[2, 1, 1, "02062021", 2452, "bla"],
[0, 0, 2, "09052021", 2345, "arghh"],
[1, 0, 5, "02042021", 234, "haha"]
])
i_user = 2
i_comment = 5
for user in numpy.unique(datas.T[2]):
print("_" * 50)
print("userId {0}".format(user))
[print("comments {0}: {1}".format(i + 1, comment)) for i, comment in enumerate(datas.T[i_comment][numpy.where(datas.T[i_user] == user)])]
它会返回:
__________________________________________________
userId 1
comments 1: blobi
comments 2: uygukih
comments 3: bla
__________________________________________________
userId 2
comments 1: arghh
__________________________________________________
userId 5
comments 1: haha