Python Forum
loading a csv file into python from pandas. Variable is not recognized
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loading a csv file into python from pandas. Variable is not recognized
#1
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-f...qK4Ua35YOD[Image: open?id=1jK61rvHM_-27fstNE1S3gysJ6ao1m7_j]
Reply
#2
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).
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Checking for a recognized text in a Dataframe KDE 0 1,520 Aug-31-2021, 11:19 PM
Last Post: KDE
  How to import an xml file to Pandas sjhazard 0 2,324 Jun-08-2021, 08:19 PM
Last Post: sjhazard
  Python - Pandas writing blank files to file tdunphy 0 1,973 Jan-14-2021, 12:11 AM
Last Post: tdunphy
  JSON file Loading issue punna111 4 8,493 Jun-29-2020, 08:07 AM
Last Post: buran
  how to solve the 'NO SUCH DIRECTORY OR FILE' in pandas, python MohammedSohail 10 15,095 May-08-2020, 07:45 AM
Last Post: nnk
  Loading .csv data using Pandas zaki424160 1 2,863 Jul-15-2019, 09:48 AM
Last Post: perfringo
  Pandas melt only on one variable (leaving other in long format) amyd 0 1,934 May-08-2019, 12:10 PM
Last Post: amyd
  Read CSV data into Pandas DataSet From Variable? Oliver 7 13,795 Jul-05-2018, 03:29 AM
Last Post: answerquest
  loading a 3D array from a bin file Mark3232 1 4,667 May-04-2018, 11:36 AM
Last Post: j.crater
  Loading HUGE data from Python into SQL SERVER Sandeep 2 21,061 Jan-13-2018, 07:52 AM
Last Post: Sandeep

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020