-1

I'm using pandas to read a CSV file through a URL in Python but I receive the following error:

NameError: name 'pandas' is not defined

I have installed pandas in command prompt and was successful. My code:

import pandas as pd
url = "https://community.watsonanalytics.com/wp-content/uploads/2015/04/WA_Fn-UseC_-Sales-Win-Loss.csv"
sales_data = pd.read_csv(url)
4b0
  • 21,981
  • 30
  • 95
  • 142
Usefi
  • 1
  • There is probably a problem with the installation. Did you install it using pip? Are you sure you have installed on the same python version you are using here? – Shir May 12 '19 at 08:13
  • Which editor are you using? Is it a virtual environment? The csv I dont think can be read directly from the url but that can be resolved after the pandas part. Try doing import pandas in the terminal – Sid May 12 '19 at 08:15
  • I installed it in command prompt and by the pip of the current version of python that I have installed on my computer, version of which is 3.7.3. – Usefi May 12 '19 at 14:03

2 Answers2

0

This could be a duplicate. For earlier Pandas versions, this should work:

Pandas read_csv from url

import pandas as pd
import requests
import io

url = "https://community.watsonanalytics.com/wp-content/uploads/2015/04/WA_Fn-UseC_-Sales-Win-Loss.csv"

s = requests.get(url).content
sales_data = pd.read_csv(io.StringIO(s.decode('utf-8')))
  • unfortunately even by your guidance I received this error. – Usefi May 13 '19 at 06:33
  • Is it the same error? Edited so url is on one line. Try testing with a different url? What version of Python, Pandas are you using? This works on Pandas 0.24.2, Python 3.7. – alphaharris May 13 '19 at 14:06
0

https://www.cameronvetter.com/nn-lab2/ has the link to access the data set.

https://www.cameronvetter.com/wp-content/uploads/2018/07/WA_Fn-UseC_-Sales-Win-Loss.csv