Jimmy_Jump
Jimmy_Jump

Reputation: 27

Accessing columns in Python using Pandas

This is very basic. I am trying to access the columns in my data set. When I print them out they're not separated.

dfWeather = pd.read_csv('C:\\Users\\austi\\WMPython\\Module7\\WburgWeather.csv','r')
print('Type of dfWeather: ',type(dfWeather))
print('Column Labels; ',dfWeather.columns.values)

I get back

Type of dfWeather:  <class 'pandas.core.frame.DataFrame'>
Column Labels;  ['STATION,STATION_NAME,ELEVATION,LATITUDE,LONGITUDE,DATE,REPORTTPYE,HOURLYSKYCONDITIONS,HOURLYVISIBILITY,HOURLYPRSENTWEATHERTYPE,HOURLYDRYBULBTEMPF,HOURLYWETBULBTEMPF,HOURLYDewPointTempF,HOURLYRelativeHumidity,HOURLYWindSpeed,HOURLYWindDi'
 'ection,HOURLYWindGustSpeed,HOURLYStationP' 'essu' 'e']

When I try to access the data in those columns using commands such as:

dfWeather['ELEVATION']

I get an error. According to my book I should get the column print out along w the corresponding data.

What I think is that when I ask for the Column Labels they should each be separated with a '' as they are in the book. But Mine are not coming out that way.

Anyone know why? Or if this is not the error what is wrong?

Upvotes: 0

Views: 58

Answers (1)

dmjy
dmjy

Reputation: 1801

pd.read_csv('C:\\Users\\austi\\WMPython\\Module7\\WburgWeather.csv','r')

This second argument is considered as separator. You shouldn't use 'r'. Just remove it.

Upvotes: 1

Related Questions