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
  problem with opening csv file in pandas saratha 2 535 Jul-21-2020, 10:55 AM
Last Post: saratha
  JSON file Loading issue punna111 4 3,222 Jun-29-2020, 08:07 AM
Last Post: buran
  Can't read text file with pandas zinho 6 3,859 May-24-2020, 06:13 AM
Last Post: azajali43
  how to solve the 'NO SUCH DIRECTORY OR FILE' in pandas, python MohammedSohail 10 1,220 May-08-2020, 07:45 AM
Last Post: nnk
  Loading .csv data using Pandas zaki424160 1 1,153 Jul-15-2019, 09:48 AM
Last Post: perfringo
  Pandas melt only on one variable (leaving other in long format) amyd 0 632 May-08-2019, 12:10 PM
Last Post: amyd
  read complex file with both pandas and not Diedro 1 976 Jan-29-2019, 05:26 PM
Last Post: Larz60+
  Load .abf file and for analysis with Pandas finalcode 0 1,095 Nov-10-2018, 09:51 AM
Last Post: finalcode
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 1,935 Oct-18-2018, 09:33 PM
Last Post: volcano63
  Read CSV data into Pandas DataSet From Variable? Oliver 7 8,401 Jul-05-2018, 03:29 AM
Last Post: answerquest

Forum Jump:

User Panel Messages

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