首页 > 编程 > Python > 正文

spss、R语言、Python数据分析系列(4):python读取外部数据

2019-11-06 06:18:00
字体:
来源:转载
供稿:网友

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 380  15 0 10 1.48 391  04 0 11 1.52 422  03 0 11 1.55 443  11 1 11 1.55 554  18 1 11 1.56 482、读取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.10    2008/1/8  11.90  12.75  11.80  12.21   12.211    2008/1/9  12.10  13.03  12.05  12.94   12.942   2008/1/10  13.04  13.32  12.71  13.10   13.103   2008/1/11  13.15  14.15  13.15  13.93   13.934   2008/1/14  13.96  14.45  13.60  14.03   14.035   2008/1/15  14.00  14.18  13.70  13.97   13.976   2008/1/16  13.80  13.85  13.11  13.32   13.327   2008/1/18  13.27  13.73  12.20  12.80   12.808   2008/1/21  12.75  13.34  12.35  13.22   13.229   2008/1/22  13.08  13.20  11.90  11.90   11.9010  2008/1/23  11.00  11.40  10.71  10.71   10.7111  2008/1/24  11.30  11.47  11.00  11.17   11.1712   2008/1/7  11.97  12.14  11.70  11.90   11.9013   2008/1/8  11.90  12.75  11.80  12.21   12.2114   2008/1/9  12.10  13.03  12.05  12.94   12.9415  2008/1/10  13.04  13.32  12.71  13.10   13.1016  2008/1/11  13.15  14.15  13.15  13.93   13.9317  2008/1/14  13.96  14.45  13.60  14.03   14.0318  2008/1/15  14.00  14.18  13.70  13.97   13.9719  2008/1/16  13.80  13.85  13.11  13.32   13.3220  2008/1/18  13.27  13.73  12.20  12.80   12.8021  2008/1/21  12.75  13.34  12.35  13.22   13.2222  2008/1/22  13.08  13.20  11.90  11.90   11.9023  2008/1/23  11.00  11.40  10.71  10.71   10.7124  2008/1/24  11.30  11.47  11.00  11.17   11.1725   2008/1/7  11.97  12.14  11.70  11.90   11.9026   2008/1/8  11.90  12.75  11.80  12.21   12.2127   2008/1/9  12.10  13.03  12.05  12.94   12.9428  2008/1/10  13.04  13.32  12.71  13.10   13.1029  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.2248  2008/1/22  13.08  13.20  11.90  11.90   11.9049  2008/1/23  11.00  11.40  10.71  10.71   10.7150  2008/1/24  11.30  11.47  11.00  11.17   11.1751   2008/1/7  11.97  12.14  11.70  11.90   11.9052   2008/1/8  11.90  12.75  11.80  12.21   12.2153   2008/1/9  12.10  13.03  12.05  12.94   12.9454  2008/1/10  13.04  13.32  12.71  13.10   13.1055  2008/1/11  13.15  14.15  13.15  13.93   13.9356  2008/1/14  13.96  14.45  13.60  14.03   14.0357  2008/1/15  14.00  14.18  13.70  13.97   13.9758  2008/1/16  13.80  13.85  13.11  13.32   13.3259  2008/1/18  13.27  13.73  12.20  12.80   12.8060  2008/1/21  12.75  13.34  12.35  13.22   13.2261  2008/1/22  13.08  13.20  11.90  11.90   11.9062  2008/1/23  11.00  11.40  10.71  10.71   10.7163  2008/1/24  11.30  11.47  11.00  11.17   11.1764   2008/1/7  11.97  12.14  11.70  11.90   11.9065   2008/1/8  11.90  12.75  11.80  12.21   12.2166   2008/1/9  12.10  13.03  12.05  12.94   12.9467  2008/1/10  13.04  13.32  12.71  13.10   13.1068  2008/1/11  13.15  14.15  13.15  13.93   13.9369  2008/1/14  13.96  14.45  13.60  14.03   14.0370  2008/1/15  14.00  14.18  13.70  13.97   13.9771  2008/1/16  13.80  13.85  13.11  13.32   13.3272  2008/1/18  13.27  13.73  12.20  12.80   12.8073  2008/1/21  12.75  13.34  12.35  13.22   13.2274  2008/1/22  13.08  13.20  11.90  11.90   11.9075  2008/1/23  11.00  11.40  10.71  10.71   10.7176  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.10           2008-01-08  11.90  12.75  11.80  12.21   12.211           2008-01-09  12.10  13.03  12.05  12.94   12.942           2008-01-10  13.04  13.32  12.71  13.10   13.103           2008-01-11  13.15  14.15  13.15  13.93   13.934           2008-01-14  13.96  14.45  13.60  14.03   14.035           2008-01-15  14.00  14.18  13.70  13.97   13.976           2008-01-16  13.80  13.85  13.11  13.32   13.327           2008-01-18  13.27  13.73  12.20  12.80   12.808           2008-01-21  12.75  13.34  12.35  13.22   13.229           2008-01-22  13.08  13.20  11.90  11.90   11.9010          2008-01-23  11.00  11.40  10.71  10.71   10.7111          2008-01-24  11.30  11.47  11.00  11.17   11.1712          2008-01-07  11.97  12.14  11.70  11.90   11.9013          2008-01-08  11.90  12.75  11.80  12.21   12.2114          2008-01-09  12.10  13.03  12.05  12.94   12.9415          2008-01-10  13.04  13.32  12.71  13.10   13.1016          2008-01-11  13.15  14.15  13.15  13.93   13.9317          2008-01-14  13.96  14.45  13.60  14.03   14.0318          2008-01-15  14.00  14.18  13.70  13.97   13.9719          2008-01-16  13.80  13.85  13.11  13.32   13.3220          2008-01-18  13.27  13.73  12.20  12.80   12.8021          2008-01-21  12.75  13.34  12.35  13.22   13.2222          2008-01-22  13.08  13.20  11.90  11.90   11.9023          2008-01-23  11.00  11.40  10.71  10.71   10.7124          2008-01-24  11.30  11.47  11.00  11.17   11.1725          2008-01-07  11.97  12.14  11.70  11.90   11.9026          2008-01-08  11.90  12.75  11.80  12.21   12.2127          2008-01-09  12.10  13.03  12.05  12.94   12.9428          2008-01-10  13.04  13.32  12.71  13.10   13.1029          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.2248          2008-01-22  13.08  13.20  11.90  11.90   11.9049          2008-01-23  11.00  11.40  10.71  10.71   10.7150          2008-01-24  11.30  11.47  11.00  11.17   11.1751          2008-01-07  11.97  12.14  11.70  11.90   11.9052          2008-01-08  11.90  12.75  11.80  12.21   12.2153          2008-01-09  12.10  13.03  12.05  12.94   12.9454          2008-01-10  13.04  13.32  12.71  13.10   13.1055          2008-01-11  13.15  14.15  13.15  13.93   13.9356          2008-01-14  13.96  14.45  13.60  14.03   14.0357          2008-01-15  14.00  14.18  13.70  13.97   13.9758          2008-01-16  13.80  13.85  13.11  13.32   13.3259          2008-01-18  13.27  13.73  12.20  12.80   12.8060          2008-01-21  12.75  13.34  12.35  13.22   13.2261          2008-01-22  13.08  13.20  11.90  11.90   11.9062          2008-01-23  11.00  11.40  10.71  10.71   10.7163          2008-01-24  11.30  11.47  11.00  11.17   11.1764          2008-01-07  11.97  12.14  11.70  11.90   11.9065          2008-01-08  11.90  12.75  11.80  12.21   12.2166          2008-01-09  12.10  13.03  12.05  12.94   12.9467          2008-01-10  13.04  13.32  12.71  13.10   13.1068          2008-01-11  13.15  14.15  13.15  13.93   13.9369          2008-01-14  13.96  14.45  13.60  14.03   14.0370          2008-01-15  14.00  14.18  13.70  13.97   13.9771          2008-01-16  13.80  13.85  13.11  13.32   13.3272          2008-01-18  13.27  13.73  12.20  12.80   12.8073          2008-01-21  12.75  13.34  12.35  13.22   13.2274          2008-01-22  13.08  13.20  11.90  11.90   11.9075          2008-01-23  11.00  11.40  10.71  10.71   10.7176          2008-01-24  11.30  11.47  11.00  11.17   11.17[77 rows x 6 columns]4、读取spss格式

import savReaderWriterdf4=savReaderWriter.SavReader('C:/Users/Administrator/Desktop/spss/数据/SPSS练习数据/data02-01.sav')


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表