AttributeError: 'DataFrame' object has no attribute 'record_high'
AttributeError: 'DataFrame' object has no attribute 'record_high'
我的代码
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)
我的数据
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
当我 运行 它时,它给我一个错误提示 AttributeError: 'DataFrame' object has no attribute 'record_high' 但显然有那个属性。有人有解决办法吗?
您的数据中可能存在间距错误。尝试通过 (df[' record_high'])
.
访问该列
如果是这样,运行
df.columns = df.columns.str.strip()
阅读 df
之后。然后你应该可以访问
df['record_high']
我的代码
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)
我的数据
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
当我 运行 它时,它给我一个错误提示 AttributeError: 'DataFrame' object has no attribute 'record_high' 但显然有那个属性。有人有解决办法吗?
您的数据中可能存在间距错误。尝试通过 (df[' record_high'])
.
如果是这样,运行
df.columns = df.columns.str.strip()
阅读 df
之后。然后你应该可以访问
df['record_high']