DataFrame数据类型
In import pandas as pd
In import numpy as np
In dtaes=['2016-01-01','2016-01-02','2016-01-03','2016-01-04','2016-01-05','2016-01-06']
In dates=pd.to_datetime(dates)
In dates
Out
DatetimeIndex(['2016-01-01','2016-01-02','2016-01-03','2016-01-04','2016-01-05','2016-01-06'],dtype='datetime64[ns]',freq=None)
In df=pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
Out
A B C D
2016-01-01 -0.924813 1.011836 -0.312846 0.773170
2016-01-02 0.462387 -0.747073 1.064430 0.598022
2016-01-03 0.318700 -0.357701 -1.503945 -0.417211
2016-01-04 -0.185249 0.398682 1.541127 -0.968151
2016-01-05 1.161603 -0.634552 0.125405 -1.496913
2016-01-06 -0.796077 0.108933 0.950862 0.452035
pd.read_table('data_file',sep='\t',header=None,names=None) #读取文件,header=0说明将第0行作为列名
df=pd.read_csv('filepath/test.csv',header=None,sep=',')
读取MYSQL数据库
import pandas as pd
import MySQLdb
mysql_cn=MySQLdb.connect(host='localhost','port3306,user='root',passwd='pwd123',db='stock')
df=pd.read_sql('select * from company limit 10;', con=mysql_cn)
mysql_cn.close()
df.head(3)
df.tail(4)
In df.columns
Out Index(['A','B','C','D'],dtype='object')
In df.index
Out DatetimeIndex(['2016-01-01','2016-01-02','2016-01-03','2016-01-04','2016-01-05','2016-01-06'],dtype='datetime64[ns]',freq=None)
In df.values
Out
array([[-0.924813, 1.011836, -0.312846, 0.773170],
[0.462387, -0.747073, 1.064430, 0.598022],
[0.318700, -0.357701, -1.503945, -0.417211],
[-0.18524, 0.398682, 1.541127, -0.968151],
[1.161603, -0.634552, 0.125405, -1.496913],
[-0.796077, 0.108933, 0.950862, 0.452035]])
df.describe()




















排序

















浙公网安备 33010602011771号