Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在大型数据框中搜索特定日期。data_value日期在列中可能有多个值。找到日期后,我从与该数据关联的一组可能值中提取最大值。
data_value
有没有办法让这更有效?它现在运行缓慢。
max_temps = [] for date in dates: value = data_w[data_w['Date']==date]['Data_Value'].max() max_temps.append(value)
如果我正确理解了您的问题,那么您需要这样,
temp=data_w[data_w['Date'].isin(dates)] print temp.groupby('Date')['Data_Value'].max()
解释:
首先应用isin在您的大型数据框中,然后应用groupby并从中max取出
isin
groupby
max