【发布时间】:2020-04-09 13:54:34
【问题描述】:
我有一个这样的系列:
s = pd.Series({10: np.array([[0.72260683, 0.27739317, 0. ],
[0.7187053 , 0.2812947 , 0. ],
[0.71435467, 0.28564533, 1. ],
[0.3268072 , 0.6731928 , 0. ],
[0.31941951, 0.68058049, 1. ],
[0.31260015, 0.68739985, 0. ]]),
20: np.array([[0.7022099 , 0.2977901 , 0. ],
[0.6983866 , 0.3016134 , 0. ],
[0.69411673, 0.30588327, 1. ],
[0.33857735, 0.66142265, 0. ],
[0.33244109, 0.66755891, 1. ],
[0.32675582, 0.67324418, 0. ]]),
20: np.array([[0.68811957, 0.34188043, 0. ],
[0.68425783, 0.31574217, 0. ],
[0.67994496, 0.32005504, 1. ],
[0.34872593, 0.66127407, 1. ],
[0.34276171, 0.65723829, 1. ],
[0.33722803, 0.66277197, 0. ]]),
38: np.array([[0.68811957, 0.31188043, 0. ],
[0.68425783, 0.31574217, 0. ],
[0.67994496, 0.32005504, 1. ],
[0.34872593, 0.65127407, 0. ],
[0.34276171, 0.65723829, 1. ],
[0.33722803, 0.66277197, 0. ]]),
np.nan: np.nan}
)
我想用np.array([1, 4, 1, 5]) 或np.array([1, 4, 1, np.nan]) 对其进行子集化,返回np.nan,无论索引数组的最后一个元素的值是什么。我怎样才能做到这一点?
请注意,我不能简单地删除系列的最后一个元素。
【问题讨论】:
标签: python arrays pandas numpy