0

I'm trying to import a CSV file with data and then do calculations with the data, the file is made as a list string. I'm trying to replace all the ' ' with '0' in every list that is in the CSV file. Looking for any advice

My current code:

import CSV

with open('Superheroes.csv', 'r') as csvfile:
    first_line = csvfile.readline()
    super_reader = csv.reader(csvfile, delimiter=',')

for vote in super_reader:
    vote.pop(0)
    print(vote)

csvfile.close()

That is what I'm currently getting

2
  • I don't think those work because I'm working with lists, not strings... I tried some of their solutions and got an error saying: 'list' object has no attribute 'split'. Commented Sep 29, 2020 at 19:47
  • Instead of data.split(',') you already have vote Commented Sep 29, 2020 at 20:04

1 Answer 1

0

Try this one:

for vote in super_reader:
    list = [(x if x else '0') for x in vote]
    print(list)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.