Python读取外部数据也比较简单,最常用的有pandas 和numpy模块
1、读取txt格式
import pandas as pd df1=pd.read_table('C:/Users/Administrator/Desktop/spss/数据/SPSS练习数据/data02-02a.txt') 06 0 10 1.46 38 0 15 0 10 1.48 39 1 04 0 11 1.52 42 2 03 0 11 1.55 44 3 11 1 11 1.55 55 4 18 1 11 1.56 48
2、读取csv格式
df2=pd.read_csv('C:/Users/Administrator/Desktop/spss/数据/SPSS练习数据.csv') df2 2008/1/7 11.97 12.14 11.7 11.9 11.9.1 0 2008/1/8 11.90 12.75 11.80 12.21 12.21 1 2008/1/9 12.10 13.03 12.05 12.94 12.94 2 2008/1/10 13.04 13.32 12.71 13.10 13.10 3 2008/1/11 13.15 14.15 13.15 13.93 13.93 4 2008/1/14 13.96 14.45 13.60 14.03 14.03 5 2008/1/15 14.00 14.18 13.70 13.97 13.97 6 2008/1/16 13.80 13.85 13.11 13.32 13.32 7 2008/1/18 13.27 13.73 12.20 12.80 12.80 8 2008/1/21 12.75 13.34 12.35 13.22 13.22 9 2008/1/22 13.08 13.20 11.90 11.90 11.90 10 2008/1/23 11.00 11.40 10.71 10.71 10.71 11 2008/1/24 11.30 11.47 11.00 11.17 11.17 12 2008/1/7 11.97 12.14 11.70 11.90 11.90 13 2008/1/8 11.90 12.75 11.80 12.21 12.21 14 2008/1/9 12.10 13.03 12.05 12.94 12.94 15 2008/1/10 13.04 13.32 12.71 13.10 13.10 16 2008/1/11 13.15 14.15 13.15 13.93 13.93 17 2008/1/14 13.96 14.45 13.60 14.03 14.03 18 2008/1/15 14.00 14.18 13.70 13.97 13.97 19 2008/1/16 13.80 13.85 13.11 13.32 13.32 20 2008/1/18 13.27 13.73 12.20 12.80 12.80 21 2008/1/21 12.75 13.34 12.35 13.22 13.22 22 2008/1/22 13.08 13.20 11.90 11.90 11.90 23 2008/1/23 11.00 11.40 10.71 10.71 10.71 24 2008/1/24 11.30 11.47 11.00 11.17 11.17 25 2008/1/7 11.97 12.14 11.70 11.90 11.90 26 2008/1/8 11.90 12.75 11.80 12.21 12.21 27 2008/1/9 12.10 13.03 12.05 12.94 12.94 28 2008/1/10 13.04 13.32 12.71 13.10 13.10 29 2008/1/11 13.15 14.15 13.15 13.93 13.93 .. ... ... ... ... ... ... 47 2008/1/21 12.75 13.34 12.35 13.22 13.22 48 2008/1/22 13.08 13.20 11.90 11.90 11.90 49 2008/1/23 11.00 11.40 10.71 10.71 10.71 50 2008/1/24 11.30 11.47 11.00 11.17 11.17 51 2008/1/7 11.97 12.14 11.70 11.90 11.90 52 2008/1/8 11.90 12.75 11.80 12.21 12.21 53 2008/1/9 12.10 13.03 12.05 12.94 12.94 54 2008/1/10 13.04 13.32 12.71 13.10 13.10 55 2008/1/11 13.15 14.15 13.15 13.93 13.93 56 2008/1/14 13.96 14.45 13.60 14.03 14.03 57 2008/1/15 14.00 14.18 13.70 13.97 13.97 58 2008/1/16 13.80 13.85 13.11 13.32 13.32 59 2008/1/18 13.27 13.73 12.20 12.80 12.80 60 2008/1/21 12.75 13.34 12.35 13.22 13.22 61 2008/1/22 13.08 13.20 11.90 11.90 11.90 62 2008/1/23 11.00 11.40 10.71 10.71 10.71 63 2008/1/24 11.30 11.47 11.00 11.17 11.17 64 2008/1/7 11.97 12.14 11.70 11.90 11.90 65 2008/1/8 11.90 12.75 11.80 12.21 12.21 66 2008/1/9 12.10 13.03 12.05 12.94 12.94 67 2008/1/10 13.04 13.32 12.71 13.10 13.10 68 2008/1/11 13.15 14.15 13.15 13.93 13.93 69 2008/1/14 13.96 14.45 13.60 14.03 14.03 70 2008/1/15 14.00 14.18 13.70 13.97 13.97 71 2008/1/16 13.80 13.85 13.11 13.32 13.32 72 2008/1/18 13.27 13.73 12.20 12.80 12.80 73 2008/1/21 12.75 13.34 12.35 13.22 13.22 74 2008/1/22 13.08 13.20 11.90 11.90 11.90 75 2008/1/23 11.00 11.40 10.71 10.71 10.71 76 2008/1/24 11.30 11.47 11.00 11.17 11.17 [77 rows x 6 columns]
3、读取excel格式
df3=pd.read_excel('C:/Users/Administrator/Desktop/spss/数据/SPSS练习数据.xlsx') df3 2008-01-07 00:00:00 11.97 12.14 11.7 11.9 11.9.1 0 2008-01-08 11.90 12.75 11.80 12.21 12.21 1 2008-01-09 12.10 13.03 12.05 12.94 12.94 2 2008-01-10 13.04 13.32 12.71 13.10 13.10 3 2008-01-11 13.15 14.15 13.15 13.93 13.93 4 2008-01-14 13.96 14.45 13.60 14.03 14.03 5 2008-01-15 14.00 14.18 13.70 13.97 13.97 6 2008-01-16 13.80 13.85 13.11 13.32 13.32 7 2008-01-18 13.27 13.73 12.20 12.80 12.80 8 2008-01-21 12.75 13.34 12.35 13.22 13.22 9 2008-01-22 13.08 13.20 11.90 11.90 11.90 10 2008-01-23 11.00 11.40 10.71 10.71 10.71 11 2008-01-24 11.30 11.47 11.00 11.17 11.17 12 2008-01-07 11.97 12.14 11.70 11.90 11.90 13 2008-01-08 11.90 12.75 11.80 12.21 12.21 14 2008-01-09 12.10 13.03 12.05 12.94 12.94 15 2008-01-10 13.04 13.32 12.71 13.10 13.10 16 2008-01-11 13.15 14.15 13.15 13.93 13.93 17 2008-01-14 13.96 14.45 13.60 14.03 14.03 18 2008-01-15 14.00 14.18 13.70 13.97 13.97 19 2008-01-16 13.80 13.85 13.11 13.32 13.32 20 2008-01-18 13.27 13.73 12.20 12.80 12.80 21 2008-01-21 12.75 13.34 12.35 13.22 13.22 22 2008-01-22 13.08 13.20 11.90 11.90 11.90 23 2008-01-23 11.00 11.40 10.71 10.71 10.71 24 2008-01-24 11.30 11.47 11.00 11.17 11.17 25 2008-01-07 11.97 12.14 11.70 11.90 11.90 26 2008-01-08 11.90 12.75 11.80 12.21 12.21 27 2008-01-09 12.10 13.03 12.05 12.94 12.94 28 2008-01-10 13.04 13.32 12.71 13.10 13.10 29 2008-01-11 13.15 14.15 13.15 13.93 13.93 .. ... ... ... ... ... ... 47 2008-01-21 12.75 13.34 12.35 13.22 13.22 48 2008-01-22 13.08 13.20 11.90 11.90 11.90 49 2008-01-23 11.00 11.40 10.71 10.71 10.71 50 2008-01-24 11.30 11.47 11.00 11.17 11.17 51 2008-01-07 11.97 12.14 11.70 11.90 11.90 52 2008-01-08 11.90 12.75 11.80 12.21 12.21 53 2008-01-09 12.10 13.03 12.05 12.94 12.94 54 2008-01-10 13.04 13.32 12.71 13.10 13.10 55 2008-01-11 13.15 14.15 13.15 13.93 13.93 56 2008-01-14 13.96 14.45 13.60 14.03 14.03 57 2008-01-15 14.00 14.18 13.70 13.97 13.97 58 2008-01-16 13.80 13.85 13.11 13.32 13.32 59 2008-01-18 13.27 13.73 12.20 12.80 12.80 60 2008-01-21 12.75 13.34 12.35 13.22 13.22 61 2008-01-22 13.08 13.20 11.90 11.90 11.90 62 2008-01-23 11.00 11.40 10.71 10.71 10.71 63 2008-01-24 11.30 11.47 11.00 11.17 11.17 64 2008-01-07 11.97 12.14 11.70 11.90 11.90 65 2008-01-08 11.90 12.75 11.80 12.21 12.21 66 2008-01-09 12.10 13.03 12.05 12.94 12.94 67 2008-01-10 13.04 13.32 12.71 13.10 13.10 68 2008-01-11 13.15 14.15 13.15 13.93 13.93 69 2008-01-14 13.96 14.45 13.60 14.03 14.03 70 2008-01-15 14.00 14.18 13.70 13.97 13.97 71 2008-01-16 13.80 13.85 13.11 13.32 13.32 72 2008-01-18 13.27 13.73 12.20 12.80 12.80 73 2008-01-21 12.75 13.34 12.35 13.22 13.22 74 2008-01-22 13.08 13.20 11.90 11.90 11.90 75 2008-01-23 11.00 11.40 10.71 10.71 10.71 76 2008-01-24 11.30 11.47 11.00 11.17 11.17 [77 rows x 6 columns]
4、读取spss格式
import savReaderWriter df4=savReaderWriter.SavReader('C:/Users/Administrator/Desktop/spss/数据/SPSS练习数据/data02-01.sav')