没有合适的资源?快使用搜索试试~ 我知道了~
最近在倒腾一个txt文件,因为文件太大,所以给切割成了好几个小的文件,只有第一个文件有标题,从第二个开始就没有标题了。 我的需求是取出指定的列的数据,踩了些坑给研究出来了。 import pandas as pd # 我们的需求是 取出所有的姓名 # test1的内容 ''' id name score 1 张三 100 2 李四 99 3 王五 98 ''' test1 = pd.read_table("test1.txt") # 这个是带有标题的文件 names = test1["name"] # 根据标题来取值 print(names) ''' 张三 李四 王五 ''' # te
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/13736988/bg1.jpg)
如何使用如何使用pandas读取读取txt文件中指定的列文件中指定的列(有无标题有无标题)
最近在倒腾一个txt文件,因为文件太大,所以给切割成了好几个小的文件,只有第一个文件有标题,从第二个开始就没有标
题了。
我的需求是取出指定的列的数据,踩了些坑给研究出来了。
import pandas as pd
# 我们的需求是 取出所有的姓名
# test1的内容
'''
id name score
1 张三 100
2 李四 99
3 王五 98
'''
test1 = pd.read_table("test1.txt") # 这个是带有标题的文件
names = test1["name"] # 根据标题来取值
print(names)
'''
张三
李四
王五
'''
# test2的内容
'''
4 Allen 100
5 Bob 99
6 Candy 98
'''
test2 = pd.read_table("test2.txt", header=None) # 这个是没有标题的文件
names = test2[1] # 根据index来取值
print(names)
'''
Allen
Bob
Candy
'''
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38677808
- 粉丝: 2
- 资源: 939
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0