1

Hi I was wondering if there is a way to search a CSV file without importing CSV module to search by row and column.

Also how could I use re.findall to find instances of a word in a column or row

For example the genre is Horror and the movie title starts with The ..so I'd need to find the total amount of "The" movies in the horror genre

Thanks

2
  • 1
    pandas is probably the best way to handle csv's and search columns or rows. if you don't want to import the csv module, are you unwilling to import pandas? Commented Apr 24, 2021 at 14:27
  • I'd like to search by row colum without importing csv or using panda Commented Apr 24, 2021 at 14:44

1 Answer 1

1

This may be not the best solution but it works. Let's imagine you have a films.csv file with film name and author like this:

title, author
The dogs, author1
The cats, author2
Cars, author1
Houses, author3
The apples, Jobs

If you want to count the number of occurrences of film name starting by "The":

with open('films.csv', 'r') as f:
    data = f.read()
n = len(re.findall("The*", data))   
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks pac for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.