大佬教程收集整理的这篇文章主要介绍了接收 'list' 对象没有属性 'groupby' 不知道为什么,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
def read_data(fileName):
data = pd.read_csv(fileName)
newList = []
columns = ['resource name','county','National Register Date','National Register number','Longitude','Latitude','Georeference']
for index,row in data.iterrows():
sub = []
for col in columns:
index_no = data.columns.get_loc(col)
sub.append(row[index_no])
newList.append(sub)
return newList
def close_by(data,pt,LOCATIOn,lst,otherLst):
close_LOCATIOns = []
long = []
lati = []
for i in range(len(data)):
long.append(float(data[i][4]))
lati.append(float(data[i][5]))
close_LOCATIOns = [shapely.geometry.Point(lon,lat) for lon,lat in zip(long,lati)]
gdf = gpd.GeoDataFrame(data,geometry=close_LOCATIOns,crs={"init":"epsg:4326"})
pts = gdf.geometry.unary_union
ptsArray = np.array(pts)
point_tree = spatial.KDTree(ptsArray)
query = point_tree.query_ball_point([LOCATIOn.longitude,LOCATIOn.latitude],0.5)
for i in range(len(query)):
value = querY[i]
lst.append(gdf.iloc[value])
otherLst.append(gdf.iloc[value][0])
st.write("List of Nearby National Parks")
st.write(otherLst)
def county_Dict(data):
countIEs = Dict(data.groupby(['county'])['resource name'].count())
return countIEs
def bar_chart(countIEs_Dict):
x = countIEs_Dict.keys()
y = countIEs_Dict.values()
plt.bar(x,y)
plt.xticks(rotation = 45)
plt.xlabel("county")
plt.ylabel("Frequency")
plt.title("Frequency of National Parks By county")
return plt
def display_map(data,otherLst):
local = []
for i in range(len(data)):
if Data[i][0] in otherLst:
local.append(data[i][4],data[i][5])
map_df = pd.DataFrame(local,columns=['resource name','Latitude'])
vIEw_state = pdk.VIEwState(longitude=map_df['Longitude'].mean(),latitude=map_df['Latitude'].mean(),zoom=10,pitch=0)
layer = pdk.Layer('ScatterplotLayer',data=map_df,get_position='[Longitude,Latitude]',get_radius = 50,get_color = [0,255,255],pickable=TruE)
tool_tip = {'HTML': 'resource name:<br/.{resource namE}','style': {'BACkgroundcolor': 'steelblue','color': 'white'}}
map = pdk.Deck(map_style='mapBox://styles/mapBox/light-b9',initial_vIEw_state=vIEw_state,layers=[layer],tooltip = tool_tip)
st.pydeck_chart(map)
def main():
filename = 'National_Register_of_Historic_Places (3).csv'
data = read_data(fileName)
st.title("Finding NY National Parks Near You")
streetNum = st.text_input("Enter your number")
streetname = st.text_input("Enter Your Street name")
city = st.text_input("Enter your city")
lst =[]
otherLst = []
geolocator = Nominatim(user_agent="Final_Project_Python")
LOCATIOn = geolocator.geocode(f"{streetNum} {streetnamE} {City} ")
pt = Point(LOCATIOn.longitude,LOCATIOn.latitudE)
close_by(data,otherLst)
countIEs_Dict = county_Dict(data)
st.write('Map of Nearby LOCATIOns')
display_map(data,otherLst)
st.pyplot(bar_chart(data))
main()
countIEs = Dict(data.groupby(['county'])['resource name'].count())
我有一个包含 ['resource name','Georeference']
列的数据框。但是,我收到此错误,
'List' 对象没有属性 'groupby', 尝试按县分组时,即使我已将其指定为字典。
在 read_data()
中,您创建 DataFrame
并列出 newList
并执行 return newList
,因此您只返回列表,然后将此列表发送到函数 county_Dict()
(和其他功能) - 所以你一直只使用列表。
你应该
return data,newList
同时发送并获取它
dataframe,newList = read_data(fileName)
然后将 dataframe
发送到 county_Dict()
并将 newList
发送到其他函数。
但我不明白你为什么需要这个 newList
。也许您应该在所有函数中只使用 dataframe
。
以上是大佬教程为你收集整理的接收 'list' 对象没有属性 'groupby' 不知道为什么全部内容,希望文章能够帮你解决接收 'list' 对象没有属性 'groupby' 不知道为什么所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。