Python Forum
loading a csv file into python from pandas. Variable is not recognized - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: loading a csv file into python from pandas. Variable is not recognized (/thread-17223.html)



loading a csv file into python from pandas. Variable is not recognized - vijjumodi - Apr-02-2019

I am facing an error in loading a csv file into python with pandas package it is not recognizing a variable. Can you guys please help me out with this. Here is my csv file and the output in python. Thanks in anticipation


 brics = pd.read_csv ('C:\\Users\\amma\\AppData\\Local\\Programs\\Python\\Python37\\brics .csv', index_col=0)
	  

>>> "Country" in brics
	  
False
>>> "capital" in brics
	  
True
>>> "area" in brics
	  
True
https://drive.google.com/open?id=1T86S-fwsFPfs1uYD_9DcxiqK4Ua35YOD[Image: open?id=1jK61rvHM_-27fstNE1S3gysJ6ao1m7_j]


RE: loading a csv file into python from pandas. Variable is not recognized - scidam - Apr-03-2019

What is question about? Is "Country in brics" expected to be True? I just loaded data and everything works fine; You have extra space in country<space> column name; It would be better to print column names out first, e.g. by calling brics.columns; and call country in brics.columns instead (Explicit is better than implicit).


RE: loading a csv file into python from pandas. Variable is not recognized - kus - Apr-19-2019

There were 2 issues in what u were implementing.

1. The column name "country" starts with a small 'c', whereas u were using 'C' while using the statement "Country" in brics. As python is case sensitive, this shall now be "country" in brics.

2. The column named "country" is having an extra space "country<space>" which needs to be removed.

This shall solve ur problem.

Regards