用python 完成以下功能:创建一个存储了21~30的整数的Series对象,索引值为1~10,将其中小于等于25的元素赋值为0。输出参考如下
时间: 2024-03-26 09:36:22 浏览: 36
以下是实现代码:
```python
import pandas as pd
data = [21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
index = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
s = pd.Series(data, index=index)
s[s <= 25] = 0
print(s)
```
输出结果如下:
```
1 0
2 0
3 0
4 0
5 0
6 26
7 27
8 28
9 29
10 30
dtype: int64
```
阅读全文