Pandas基础
import pandas aspd
import numpy as np
#数字序列
myseries=pd.Series([1,3,5,np.nan,6,8])
print myseries
#日期序列
mydate=pd.date_range(‘20150101‘,periods=42)
print mydate
生成序列
结果如下:
0 1
1 3
2 5
3 NaN
4 6
5 8
dtype: float64
<class‘pandas.tseries.index.DatetimeIndex‘>
[2015-01-01, ..., 2015-02-11]
Length: 42, Freq: D, Timezone: None
生成数据集
# -*- coding:utf-8 -*-
"""
Created on Mon Mar 09 11:21:02 2015
@author: myhaspl@myhaspl.com
"""
print u"python数据分析\n"
import pandas as pd
import numpy as np
#日期序列
mydate=pd.date_range(‘20150101’,periods=10)
print mydate
#构造商品销量数据
mydf =pd.DataFrame(np.random.randint(0,1000,size=(10,4)),index=mydate,columns=[u‘商品A‘,u‘商品B‘,u‘商品C‘,u‘商品D‘])
#输出商品销量数据
print mydf
运行结果如下:
runfile(‘C:/Users/Administrator/Desktop/test1.py‘,wdir=r‘C:/Users/Administrator/Desktop‘)
python数据分析
<class‘pandas.tseries.index.DatetimeIndex‘>
[2015-01-01, ..., 2015-01-10]
Length: 10, Freq: D, Timezone: None
商品A 商品B 商品C 商品D
2015-01-01 369 836 908 440
2015-01-02 257 26 725 542
2015-01-03 485 694 701 172
2015-01-04 468 762 536 735
2015-01-05 828 996 852 267
2015-01-06 690 824 515 749
2015-01-07 357 740 559 157
2015-01-08 705 573 193 568
2015-01-09 285 853 600 132
2015-01-10 681 437 935 93
原文地址:http://blog.csdn.net/myhaspl/article/details/44153173