pandas数据集删除指定列后,对剩下的数据进行求和,要求保留求和结果在85~105区间内的数据,输出不符合要求的文物采样点而不是索引,一共有1个数据集需要如此处理,数据集名称如下df2
时间: 2024-03-05 17:54:52 浏览: 19
好的,可以使用如下代码实现:
```python
import pandas as pd
# 读取数据集
df2 = pd.read_csv('df2.csv')
# 删除指定列
df2 = df2.drop(columns=['col1', 'col2'])
# 对剩下的数据进行求和
sum2 = df2.sum(axis=1)
# 筛选符合要求的数据
result2 = df2[(sum2 >= 85) & (sum2 <= 105)]
# 输出不符合要求的文物采样点
print('df2不符合要求的文物采样点:')
print(df2[~df2.index.isin(result2.index)].iloc[:, 0].tolist())
```
其中,`iloc`函数可以根据索引位置选择指定的行和列,`tolist`函数可以将Series类型的数据转换为列表类型。
相关问题
pandas数据集删除指定列后,对剩下的数据进行求和,要求保留求和结果在85~105区间内的数据,输出不符合要求的物品名称,一共有2个数据集需要如此处理,数据集名称如下df2,df3
好的,可以使用如下代码实现:
```python
import pandas as pd
# 读取数据集
df2 = pd.read_csv('df2.csv')
df3 = pd.read_csv('df3.csv')
# 删除指定列
df2 = df2.drop(columns=['col1', 'col2'])
df3 = df3.drop(columns=['col1', 'col2'])
# 对剩下的数据进行求和
sum2 = df2.sum(axis=1)
sum3 = df3.sum(axis=1)
# 筛选符合要求的数据
result2 = df2[(sum2 >= 85) & (sum2 <= 105)]
result3 = df3[(sum3 >= 85) & (sum3 <= 105)]
# 输出不符合要求的物品名称
print('df2不符合要求的物品名称:')
print(df2[~df2.index.isin(result2.index)].index.tolist())
print('df3不符合要求的物品名称:')
print(df3[~df3.index.isin(result3.index)].index.tolist())
```
其中,`drop`函数可以删除指定列,`sum`函数可以对剩下的数据进行求和,`[]`运算符可以根据条件筛选符合要求的数据,`~`运算符可以取反,`isin`函数可以判断一个索引是否在指定的索引列表中。
pandas数据集删除指定列后,对剩下的数据进行求和,要求保留求和结果在85~105区间内的数据,输出不在区间内的数据在【‘文物采样点’】列名中的数据,一共有1个数据集需要如此处理,数据集名称如下df2
好的,可以使用如下代码实现:
```python
import pandas as pd
# 读取数据集
df2 = pd.read_csv('df2.csv')
# 删除指定列
df2 = df2.drop(columns=['col1', 'col2'])
# 对剩下的数据进行求和
sum2 = df2.sum(axis=1)
# 筛选符合要求的数据
result2 = df2[(sum2 >= 85) & (sum2 <= 105)]
# 输出不符合要求的文物采样点
print('df2不符合要求的文物采样点:')
print(df2[~df2.index.isin(result2.index)]['文物采样点'].tolist())
```
其中,`~`运算符可以取反,`isin`函数可以判断一个索引是否在指定的索引列表中,`tolist`函数可以将Series类型的数据转换为列表类型。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)