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