博客
关于我
【数据分析与预处理】 ---- 数据的提取与筛选
阅读量:328 次
发布时间:2019-03-04

本文共 827 字,大约阅读时间需要 2 分钟。


文章目录


1.读取数据

data = pd.read_csv("G:\Projects\pycharmeProject\大数据比赛\data\mysql.csv")print(data.shape)

2.数据的提取与筛选

2.1 增加某一列

2.1.1 以原数据的索引添加列

data['index'] = data.index

在这里插入图片描述

2.1.2 以国家数据添加列

data['country'] = data['国家']

在这里插入图片描述


2.2 删除特定列 drop(columns=’?’)

data_drop = data.drop(columns='index')

在这里插入图片描述


2.3 删除特定行 — 根据索引删除 drop(index=[?],axis=1)

data_drop_index = data.drop(index=1,axis=1)data_drop_mulIndex = data.drop(index=[1,2,3,4,5],axis=1)

在这里插入图片描述

在这里插入图片描述


2.4 删除特定值的记录

2.4.1 找出特定值所在行进行筛选

方法一 drop(index=data_target_index,axis=1)

data_condition = data['城市'] == '阿坝'data_target = data.loc[data_condition]data_target_index = data_target.indexdata_drop_target_index = data.drop(index=data_target_index,axis=1)

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


方法二 loc[~data_condition]

data_condition = data['城市'].isin(['阿坝'])data_target = data.loc[data_condition]data_without_target = data.loc[~data_condition]   # 加个~号

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述


转载地址:http://bzeq.baihongyu.com/

你可能感兴趣的文章
Navicat通过存储过程批量插入mysql数据
查看>>
Navicat(数据库可视化操作软件)安装、配置、测试
查看>>
navigationController
查看>>
NB-IOT使用LWM2M移动onenet基础通信套件对接之APN设置
查看>>
NBear简介与使用图解
查看>>
Vue过滤器_使用过滤器进行数据格式化操作---vue工作笔记0015
查看>>
Ncast盈可视 高清智能录播系统 IPSetup.php信息泄露+RCE漏洞复现(CVE-2024-0305)
查看>>
NCNN中的模型量化解决方案:源码阅读和原理解析
查看>>
NCNN源码学习(1):Mat详解
查看>>
nc命令详解
查看>>
NC综合漏洞利用工具
查看>>
ndarray 比 recarray 访问快吗?
查看>>
ndk-cmake
查看>>
NdkBootPicker 使用与安装指南
查看>>
ndk特定版本下载
查看>>
NDK编译错误expected specifier-qualifier-list before...
查看>>
Neat Stuff to Do in List Controls Using Custom Draw
查看>>
Necurs僵尸网络攻击美国金融机构 利用Trickbot银行木马窃取账户信息和欺诈
查看>>
Needle in a haystack: efficient storage of billions of photos 【转】
查看>>
NeHe OpenGL教程 07 纹理过滤、应用光照
查看>>