python 中 read_table 函数
001、
[root@PC1 test3]# ls a.txt [root@PC1 test3]# cat a.txt ## 测试文件 10 2 3 0 3 6 6 12 1 1 5 1 2 2 2 4 2 26 8 3 33 34 5 3 [root@PC1 test3]# python ## 启用python Python 3.11.3 (main, May 9 2023, 00:27:08) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information.
002、
>>> import os >>> import pandas as pd ## 导入包 >>> os.listdir() ## 列出文件 ['a.txt'] >>> a=pd.read_table("a.txt", sep = "\t", header = None) ## 读入文件 >>> A Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'A' is not defined. Did you mean: 'a'? >>> a 0 1 2 3 4 5 0 10 2 3 0 3 6 1 6 12 1 1 5 1 2 2 2 2 4 2 26 3 8 3 33 34 5 3
003、基本属性
>>> a 0 1 2 3 4 5 0 10 2 3 0 3 6 1 6 12 1 1 5 1 2 2 2 2 4 2 26 3 8 3 33 34 5 3 >>> type(a) <class 'pandas.core.frame.DataFrame'> >>> a.head(2) 0 1 2 3 4 5 0 10 2 3 0 3 6 1 6 12 1 1 5 1 >>> a.tail(1) 0 1 2 3 4 5 3 8 3 33 34 5 3 >>> a.max() 0 10 1 12 2 33 3 34 4 5 5 26 dtype: int64 >>> a.shape (4, 6) >>> a.dtypes 0 int64 1 int64 2 int64 3 int64 4 int64 5 int64 dtype: object >>> a.describe() 0 1 2 3 4 5 count 4.00000 4.000000 4.00000 4.000000 4.00 4.000000 mean 6.50000 4.750000 9.75000 9.750000 3.75 9.000000 std 3.41565 4.856267 15.52149 16.255768 1.50 11.518102 min 2.00000 2.000000 1.00000 0.000000 2.00 1.000000 25% 5.00000 2.000000 1.75000 0.750000 2.75 2.500000 50% 7.00000 2.500000 2.50000 2.500000 4.00 4.500000 75% 8.50000 5.250000 10.50000 11.500000 5.00 11.000000 max 10.00000 12.000000 33.00000 34.000000 5.00 26.000000
分类:
python
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-05-16 linux 中正则表达式同时匹配字母和数字
2022-05-16 正则表达式中常见特殊字符的意义
2022-05-16 正则表达式中 + 的作用
2022-05-16 正则表达式中?和*的区别
2022-05-16 正则表达式中.* 和 .*?的区别
2022-05-16 正则表达式中.和*的区别
2022-05-16 linux 中 sed预存储命令