pandas 条件搜索返回列表的方法
作者:benofdog 时间:2022-09-16 14:46:34
pandas中常用的一件事情就是对特定条件进行搜索,那么这里介绍使用pandas搜索方式,本案例使用的pandas是anaconda中的,可以下载任意的anaconda进行安装都会带有。
首先导入包
import pandas as pd
import os
然后需要构建一个csv文件存上文件。比如我们有一个叫test.csv的文件,文件有三个列的表头,id、name、address我们想知道一个人的名字的id与地址就可以写成
test_csv = pd.read_csv('/test.csv', encoding='gb2312')# 如果有中文就要gb2312
info_Joan = test_csv[test_csv['name']='Join] # 这样我们就获得了Joan的id以及address 信息
或者是
info_Joan =test_csv[test_csv['name']isin(['Join'])]
余下的就是你想要的操作了。比如取得values的或者组成列表
[list(x) for x in info_Joan['id'].values]
来源:https://blog.csdn.net/benofdog/article/details/72588209
标签:pandas,搜索,列表
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用Python实现从各个子文件夹中复制指定文件的方法
2023-11-09 12:04:05
PythonWeb项目Django部署在Ubuntu18.04腾讯云主机上
2021-02-11 11:15:33
![](https://img.aspxhome.com/file/2023/1/77921_0s.png)
OpenCV+MediaPipe实现手部关键点识别
2021-08-02 10:32:24
![](https://img.aspxhome.com/file/2023/4/114744_0s.png)
keras多显卡训练方式
2022-05-01 02:50:21
python将字母转化为数字实例方法
2021-12-04 03:40:17
![](https://img.aspxhome.com/file/2023/0/109890_0s.png)
python类继承用法实例分析
2022-01-25 16:44:13
JS实现仿Windows经典风格的选项卡Tab切换代码
2023-08-25 05:33:54
![](https://img.aspxhome.com/file/2023/2/56172_0s.png)
Windows平台Python编程必会模块之pywin32介绍
2023-11-05 10:45:35
![](https://img.aspxhome.com/file/2023/7/63917_0s.jpg)
Python使用sftp实现传文件夹和文件
2021-09-30 12:27:37
![](https://img.aspxhome.com/file/2023/1/76881_0s.jpg)
Python3网络爬虫之使用User Agent和代理IP隐藏身份
2022-03-05 13:13:07
![](https://img.aspxhome.com/file/2023/5/79625_0s.png)
Pycharm中出现ImportError:DLL load failed:找不到指定模块的解决方法
2021-09-04 06:14:32
![](https://img.aspxhome.com/file/2023/5/110285_0s.jpg)
Python的GUI框架PySide的安装配置教程
2021-09-12 05:51:20
![](https://img.aspxhome.com/file/2023/9/105439_0s.png)
Python tkinter库绘制春联和福字的示例详解
2022-03-05 06:29:04
![](https://img.aspxhome.com/file/2023/0/95930_0s.png)
python实现简单tftp(基于udp协议)
2021-01-30 15:01:23
![](https://img.aspxhome.com/file/2023/9/114599_0s.jpg)
python实现记事本功能
2022-04-02 09:54:19
![](https://img.aspxhome.com/file/2023/1/75221_0s.gif)
Python Request爬取seo.chinaz.com百度权重网站的查询结果过程解析
2022-12-01 07:16:59
![](https://img.aspxhome.com/file/2023/0/102930_0s.png)
python获取本地计算机名字的方法
2022-01-26 10:04:32
天气预报调用代码
2008-11-18 15:59:00
![](https://img.aspxhome.com/file/UploadPic/200811/18/g20081115162112-94s.jpg)
IE7的web标准之道 Ⅰ
2008-08-13 12:42:00
![](https://img.aspxhome.com/file/UploadPic/20088/13/200881312500620s.gif)
Python如何获取文件路径/目录
2021-09-01 09:05:18