I have the data in the form like
How do I separate or filter the rows based on the keywords of the genre(horror, thriller, etc) and store them for further processing(sorting)?
I have the data in the form like
How do I separate or filter the rows based on the keywords of the genre(horror, thriller, etc) and store them for further processing(sorting)?
You could maybe do:
f = open("myfile.csv", "r")
romance_mov = []
for line in f:
if "romance" in line.split(",")[4].lower():
romance_mov.append(line)
f.close()
Which would give you a list romance_mov
with all the lines that are of genre 'romance'.
EDIT: For sorting the lines based on the value in hitFlop, you could then do:
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]