#๐ how to change data type of csv.reader to something else
6 messages ยท Page 1 of 1 (latest)
@gentle bridge
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.
Closes after a period of inactivity, or when you send !close.
"'py
import csv
import matplotlib.pyplot as plt
def read_csv_data(filepath):
data = {
'years': [],
'americaExports': [],
'asiaExports': [],
'europeExports': [],
'oceaniaExports': [],
'africaExports': [],
'euExports': []
}
with open(filepath, mode='r', newline='') as file:
csvreader = csv.reader(file)
next(csvreader) # Skip header row
for row in csvreader:
data['years'].append(int(row[0]))
data['americaExports'].append(float(row[1]))
data['asiaExports'].append(float(row[1]))
data['europeExports'].append(float(row[1]))
data['oceaniaExports'].append(float(row[1]))
data['africaExports'].append(float(row[1]))
data['euExports'].append(float(row[1]))
'''
Why don't you use pandas and then change the dtypes to what suits you dataset
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.