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

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

读取数据

使用 pd.read_csv 读取数据文件:

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

数据的提取与筛选

增加某一列

以原数据的索引添加列
data['index'] = data.index
以国家数据添加列
data['country'] = data['国家']

删除特定列

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

删除特定行

data_drop_index = data.drop(index=1, axis=1)data_drop_mulIndex = data.drop(index=[1,2,3,4,5], 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['城市'].isin(['阿坝'])data_without_target = data.loc[~data_condition]

结论

通过以上方法,我们可以对数据进行必要的提取和筛选,确保数据的完整性和准确性。

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

你可能感兴趣的文章
openSUSE推出独立 GUI 包管理工具:YQPkg,简化了整个软件包管理流程
查看>>
OpenVP共用账号 一个账号多台电脑登录
查看>>
OpenVSwtich(OVS)Vlan间路由实战 附实验环境
查看>>
Openwrt LuCI模块练习详细步骤
查看>>
openwrt_git_pull命令提示merger冲突时如何解决?
查看>>
OpenWrt包管理软件opkg的使用(极路由)
查看>>
OpenWrt固件编译刷机完全总结
查看>>
Open××× for Linux搭建之二
查看>>
Open×××有线网络时使用正常,无线网络时使用报错的解决方案
查看>>
Opera Mobile Classic Emulator
查看>>
Operation not supported on read-only collection 的解决方法 - [Windows Phone开发技巧系列1]
查看>>
OperationResult
查看>>
Operations Manager 2007 R2系列之仪表板(多)视图
查看>>
operator new and delete
查看>>
operator new 与 operator delete
查看>>
operator() error
查看>>
OPPO K3在哪里打开USB调试模式的完美方法
查看>>
oppo后端16连问
查看>>
Optional类:避免NullPointerException
查看>>
Optional讲解
查看>>