博客
关于我
【数据分析与预处理】 ---- 数据的提取与筛选
阅读量: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/

你可能感兴趣的文章
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>
mysql5.7安装
查看>>
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>