简体   繁体   English

如何切片熊猫数据框地理定位

[英]How to slice pandas dataframe geolocation

I have read in a bunch of data into my dataframe (df) from a CSV file. 我已经从CSV文件中将一堆数据读入了数据框(df)。 One of the fields is a GeoLocation (longitude, latitude) and I wish to slice out certain rows where the longitude is between 37 and 40. The CSV stores the geolocation in a column with (longitude, latitude) I am having trouble using the 'df.where()' function 其中一个字段是GeoLocation(经度,纬度),我想切出某些经度在37到40之间的行。CSV将地理位置存储在(经度,纬度)列中,我在使用' df.where()'函数

geo = df.where(df['GeoLocation'][0] < 40 & df['GeoLocation'][0] > 37)

This keeps throwing error saying 这总是抛出错误说

TypeError: 'str' object cannot be interpreted as an integer

What am i doing wrong when i am trying to slice the column? 尝试对色谱柱进行切片时我在做什么错?

Here is the code i used to pull in the data 这是我用来提取数据的代码

df = pd.concat([x for x in pd.read_csv('U.S._Chronic_Disease_Indicators__CDI_.csv', chunksize=1000)], ignore_index=True)'

You want to split up the series first, then do a filter 您要先拆分系列,然后进行过滤

df[['lat', 'long']] = df['GeoLocation'].str.split(',', expand=True).astype(float)
geo = df[(df['lat'] < 40) & (df['long'] > 37)]

Note that the [(x) & (y)] is very picky about you explicitly having all the parentheses. 请注意,[(x)&(y)]对于您明确拥有所有括号非常挑剔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM