当前位置:网站首页>Dataframe first performs grouping operation and then combines output
Dataframe first performs grouping operation and then combines output
2022-07-25 20:02:00 【RS&Hydrology】
dataframe First group operation and then merge output : It mainly uses grouping functions groupby And merge function append、concat, Specific code :
For example, group first , Delete outliers for each group of data (MAD), Then merge the processed data into one dataframe Output .
import os
import pandas as pd
from pyod.models.mad import MAD
import warnings
warnings.filterwarnings('ignore')
#%%
#test
df = pd.read_csv('./21.csv')
# print(len(df))#2273824
def fit_model(model, data, column='s'):
# fit the model and predict it
df = data.copy()
data_to_predict = data[column].to_numpy().reshape(-1, 1)
predictions = model.fit_predict(data_to_predict)
df['Predictions_1'] = predictions
return df
df_groupby = df.groupby(["class"])#group by class
frames = []
for decyear,group in df_groupby:
# print(decyear)
# print(group)
mad_model = MAD()
group_mad = fit_model(mad_model,group)
group_mad_filter = group_mad[(group_mad['Predictions_1'] == 0)]
# print(group_mad_filter)
frames.append(group_mad_filter)
result = pd.concat(frames, axis=0, names=None)
print('done!')
边栏推荐
- Sentinel simple current limiting and degradation demo problem record
- Dataloader reports an error "default_collate: batch must contain tensors, numpy arrays, numbers, dicts" when pytorch trains the model
- 各厂商网络虚拟化的优势
- Configure and install cocos2dx development environment under Tongxin UOS
- [good book recommendation] - authoritative guide to Ethernet (2nd Edition)
- When the V100 of mindpole 8 card is trained to 101 epochs, an error of reading data timeout is reported
- Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
- Six axis sensor use learning record
- JVM(二十三) -- JVM运行时参数
- Timing analysis and constraints based on xlinx (1) -- what is timing analysis? What are temporal constraints? What is temporal convergence?
猜你喜欢

相机内参矩阵K和fov的相互转换

919. 完全二叉树插入器

给容器添加3d效果的副标题

Socket error Event: 32 Error: 10053. Connection closing...Socket close

How to get started quickly in software testing
![[artifact] screenshot + mapping tool snipaste](/img/d2/a9a706a114641094e32ab5c6193f58.png)
[artifact] screenshot + mapping tool snipaste

C language learning diary 3 - realloc function

一元函数积分学_分部积分法

基于海思3559 高效率的 0延时 0拷贝 qt播放器方案

谷歌Pixel 6a屏下指纹扫描仪存在重大安全漏洞
随机推荐
Three skills of interface request merging, and the performance is directly exploded!
When AI encounters life and health, Huawei cloud builds three bridges for them
Security Basics 4 - regular expressions
Concept of IP address
【云原生 | 从零开始学Kubernetes】八、命名空间资源配额以及标签
网络爬虫原理解析「建议收藏」
统信UOS下配置安装cocos2dx开发环境
CarSim simulation quick start (XV) - ADAS sensor objects of CarSim sensor simulation (1)
03 isomorphism of tree 1
High number_ Chapter 3 learning experience and summary of multiple integral
QQ是32位还是64位软件(在哪看电脑是32位还是64位)
【神器】截图+贴图工具 Snipaste
wallys//wifi6 wifi5 router IPQ6018 IPQ4019 IPQ4029 802.11ax 802.11ac
Siemens PLM Teamcenter download, installation and use tutorial
笔记——记录一个CannotFindDataSourceException: dynamic-datasource can not find primary datasource问题解决
tiktok如何破零播放?
How does tiktok break zero?
PyTorch 模型 onnx 文件的导出和调用
4、Nacos 配置中心源码解析之 服务端启动
推荐系统专题 | MiNet:跨域CTR预测