如何在Python中使用zip函数并返回包含最大值的系列的索引?

问题描述

我正在使用zip来比较两个系列Max_Plot2015_serie,Max_Plot2005_2014_serie,并将两者的最大值返回到新系列Max_scatter2015 ['Temp_Celcius']。 如何导入相应值的索引(索引是日期)? 我是Python的新手,对功能的掌握不够

Max_scatter2015['Temp_Celcius'] = [max(value) for value in zip(Max_Plot2015_serie,Max_Plot2005_2014_serie)]

Max_Plot2005_2014_serie
2014-12-25    10.0
2014-12-26    10.0
2014-12-27    11.1
2014-12-28    13.3
2014-12-30     3.3
2014-12-31    -2.8
Name: Temp_Celcius,dtype: float64
<class 'pandas.core.series.Series'>


Max_Plot2015_serie
2015-10-02    18.9
2015-03-10     9.4
2015-02-23    -1.1
2015-06-09    25.6
Name: Temp_Celcius,dtype: float64
<class 'pandas.core.series.Series'>

Max_scatter2015
Temp_Celcius    [18.9,13.9,26.1,23.3,6.7,18.3,27.8,7.2,...
dtype: object
<class 'pandas.core.series.Series'>

解决方法

也许这就是您想要的:

xhr.send( ( s.hasContent && s.data ) || null );
,

IIUC,您可以尝试执行以下操作:

s_2014 = pd.Series(np.random.randint(0,120,365),index=pd.date_range('2014-01-01',periods=365,freq='D'))

s_2015 = pd.Series(np.random.randint(0,135,index=pd.date_range('2015-01-01',freq='D'))

按天查找最大值:

m = [max(i,j,key=lambda x: x[1]) for i,j in zip(s_2014.iteritems(),s_2015.iteritems())]
j,i = zip(*m)
s = pd.Series(i,index=j)
s

输出:

2015-01-01    104
2014-01-02    101
2014-01-03    118
2014-01-04     26
2015-01-05     98
             ... 
2015-12-27    132
2014-12-28     58
2015-12-29    110
2015-12-30    115
2015-12-31     35
Length: 365,dtype: int64

仅更新至2015年数据:

s[s.index.year == 2015]

输出:

2015-01-01     60
2015-01-03    109
2015-01-06     71
2015-01-07    113
2015-01-09      9
             ... 
2015-12-16     90
2015-12-23     98
2015-12-26    132
2015-12-27    107
2015-12-29     65
Length: 204,dtype: int64