I have extracted some data from a website into a CSV file and I need to plot a scatterplot in matplotlib from that CSV file. I only need column 2 and 3 data from the CSV file.
I'm trying to use a for loop to gather CSV data into a list and then use that to plot the scatterplot but I'm getting a "ValueError: x and y must be the same size" error.
import matplotlib.pyplot as plt
import csv
with open(cache_path + distance_csv) as csv_file:
reader = csv.reader(csv_file)
for column in reader:
city_distance = [x[1] for x in csv.reader(csv_file)]
crime_rate = [x[2] for x in csv.reader(csv_file)]
plt.scatter(city_distance, crime_rate)
plt.show()
Both columns 2 and 3 in my CSV file are the same length - 83 cells yet I am getting a ValueError. What am I missing here?