Issue
My Code
import numpy as np import pandas as pd
print('-' * 50)
filename = r'''C:\Users\Computer\Documents\Python Scripts\weather.txt'''
df = pd.read_csv(filename)
pd.set_option('display.max_columns', None)
print (df.describe())
print (df.record_high)
My data
month, avg_high, avg_low, record_high, record_low, avg_percipitation
Jan, 58, 42, 74, 22, 2.95
Feb, 61, 45, 78, 26, 3.02
Mar, 65, 48, 84, 25, 2.34
Apr, 67, 50, 92, 28, 1.02
May, 71, 53, 98, 35, 0.48
Jun, 75, 56, 107, 41, 0.11
Jul, 77, 58, 105, 44, 0.0
Aug, 77, 59, 102, 43, 0.03
Sep, 77, 57, 103, 40, 0.17
Oct, 73, 54, 96, 34, 0.81
Nov, 64, 48, 84, 30, 1.7
Dec, 58, 42, 73, 21, 2.56
When I run it, it gives me an error saying AttributeError: 'DataFrame' object has no attribute 'record_high' but there clearly is that attribute. Does anyone have a solution?
Solution
There may be a spacing error in your data. Try accessing the column by doing (df[' record_high'])
.
If that is the case, run
df.columns = df.columns.str.strip()
after you read in df
. You should then be able to access
df['record_high']
Answered By - rma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.