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
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
>>> "capital" in brics
>>> "area" in brics
True[Image: open?id=1jK61rvHM_-27fstNE1S3gysJ6ao1m7_j]
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).
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.


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with opening csv file in pandas saratha 2 534 Jul-21-2020, 10:55 AM
Last Post: saratha
  JSON file Loading issue punna111 4 3,209 Jun-29-2020, 08:07 AM
Last Post: buran
  Can't read text file with pandas zinho 6 3,830 May-24-2020, 06:13 AM
Last Post: azajali43
  how to solve the 'NO SUCH DIRECTORY OR FILE' in pandas, python MohammedSohail 10 1,193 May-08-2020, 07:45 AM
Last Post: nnk
  Loading .csv data using Pandas zaki424160 1 1,147 Jul-15-2019, 09:48 AM
Last Post: perfringo
  Pandas melt only on one variable (leaving other in long format) amyd 0 630 May-08-2019, 12:10 PM
Last Post: amyd
  read complex file with both pandas and not Diedro 1 969 Jan-29-2019, 05:26 PM
Last Post: Larz60+
  Load .abf file and for analysis with Pandas finalcode 0 1,094 Nov-10-2018, 09:51 AM
Last Post: finalcode
  Read CSV data into Pandas DataSet From Variable? Oliver 7 8,383 Jul-05-2018, 03:29 AM
Last Post: answerquest
  loading a 3D array from a bin file Mark3232 1 1,726 May-04-2018, 11:36 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

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