答案 0 :(得分:1)
您可以这样做:
f = open("myfile.csv", "r")
romance_mov = []
for line in f:
if "romance" in line.split(",")[4].lower():
romance_mov.append(line)
f.close()
哪个会给您一个列表romance_mov
,其中包含所有类型为“浪漫”的行。
编辑:为了根据hitFlop中的值对行进行排序,您可以执行以下操作:
import numpy as np
# Extract the hitFlop value for each row
hitFlop = []
for item in romance_mov:
hitFlop.append(int(item.split(",")[-1]))
# Obtain the sorted indexes
idx_sorted = np.argsort(hitFlop)
# Sort the romance movies
romance_mov_sorted = np.asarray(romance_mov)[idx_sorted]