小编Qua*_*tia的帖子

Python:在Pandas系列上使用lambda函数,if .. else

我正在尝试对存储在pandas系列对象中的一系列值应用过滤器.如果满足标准,则期望的输出是值本身,否则为零.我只能完成一半工作:

criterion = testdata.map(lambda x: x < 30 or x > 60) 
testdata[criterion] =
Date
2015-01-05    62.358615
2015-01-06    64.349507
2015-01-13    61.726110
2015-01-14    63.574864
2015-01-15    66.020421
2015-01-16    63.041819
2015-01-20    61.458298
Name: rsi, dtype: float64
Run Code Online (Sandbox Code Playgroud)

哪里:

testdata =
Date
2014-12-29    45.821073
2014-12-30    48.946830
2014-12-31    57.737593
2015-01-02    55.424047
2015-01-05    62.358615
2015-01-06    64.349507
2015-01-07    59.452935
2015-01-08    51.182115
2015-01-09    55.044419
2015-01-12    59.365017
2015-01-13    61.726110
2015-01-14    63.574864
2015-01-15    66.020421
2015-01-16    63.041819
2015-01-20    61.458298
2015-01-21    54.432635
2015-01-22    46.985675
2015-01-23    49.740981
2015-01-26    45.102370
2015-01-27    49.800855
Name: rsi, dtype: …
Run Code Online (Sandbox Code Playgroud)

python lambda if-statement time-series pandas

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

if-statement ×1

lambda ×1

pandas ×1

python ×1

time-series ×1