#๐ I am not getting expected data
28 messages ยท Page 1 of 1 (latest)
@crisp sundial
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
can you share your code?
import pandas as pd
import csv
with open('file.csv', 'r') as file:
reader = csv.reader(file)
num_cities = int(input('How many cities do you want to see? '))
for _ in range(num_cities):
city_name = input('Enter the city name: ')
for row in reader:
city, population = row.split(',')
if city == city_name:
print(f'{city} has {population} people')
break
file.close()
It looks like you're printing the reader object instead of specific data from it
Here is the code man
for starters, you don't need file.close() when using with
you also can't iterate through a csv file more than once without reopening it
they are "exhaustable"
๐ฎ
Then what should I do
you should be able to convert the reader data to a list first
Eh I got It that I had been not completed the video on CSV yet
Hm
List(reader)
โฆ?
reader = list(csv.reader(file))
ยป classmethod
ยป class
!clos
Don't worry man i got it and I am going to close it sorry if u feel it heartbreaking ๐
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.