【发布时间】:2019-09-15 00:13:05
【问题描述】:
我正在扫描按特定 ID 分组的数据框,并尝试根据我在字典中的某些长/纬度位置返回位置表面类型。数据集的问题在于它是以每秒 100 帧的速度创建的,所以我试图找到中间值,因为该点之前和之后的值不正确。
我正在使用 pandas jupyter notebook 并且有
这是我想从字典中提取位置的函数。该位置只是一个虚构的例子
pitch_boundaries = {
'Astro': {'max_long': -6.123456, 'min_long': -6.123456,
'max_lat': 53.123456, 'min_lat': 53.123456},
}
def get_loc_name(loc_df, pitch_boundaries):
for pitch_name, coord_limits in pitch_boundaries.items():
between_long_limits = loc_df['longitude'].median().between(coord_limits['min_long'], coord_limits['max_long'])
between_lat_limits = loc_df['latitude'].median().between(coord_limits['min_lat'], coord_limits['max_lat'])
if between_long_limits.any() and between_lat_limits.any():
return pitch_name
# If we get here then there is no pitch.
在这里调用
def makeAverageDataFrame(df):
pitchBounds = get_loc_name(df, pitch_boundaries)
i = len(df_average.index)
df_average.loc[i] = [pitchBounds]
最后出现错误的地方
for region, df_region in df_Will.groupby('session_id'):
makeAverageDataFrame(df_region)
实际结果# AttributeError: 'float' object has no attribute 'between'
或者如果我删除 .median(): None
我想要的是一个像
这样的新数据框|surface|
|Astro|
|Grass|
|Astro|
【问题讨论】:
标签: python pandas dictionary location