Extract csv file specific columns to list in Python

前端 未结 3 2045
既然无缘
既然无缘 2020-12-07 16:12

What I\'m trying to do is plot the latitude and longitude values of specific storms on a map using matplotlib,basemap,python, etc. My problem is that I\'m trying to extract

3条回答
  •  攒了一身酷
    2020-12-07 16:22

    This looks like a problem with line endings in your code. If you're going to be using all these other scientific packages, you may as well use Pandas for the CSV reading part, which is both more robust and more useful than just the csv module:

    import pandas
    colnames = ['year', 'name', 'city', 'latitude', 'longitude']
    data = pandas.read_csv('test.csv', names=colnames)
    

    If you want your lists as in the question, you can now do:

    names = data.name.tolist()
    latitude = data.latitude.tolist()
    longitude = data.longitude.tolist()
    

提交回复
热议问题