浅谈python的dataframe与series的创建方法
时间:2022-02-25 12:41 作者:admin610456
如下所示:
# -*- coding: utf-8 -*-import numpy as npimport pandas as pddef main(): s = pd.Series([i*2 for i in range(1,11)]) print type(s) print (s) dates = pd.date_range("20170301",periods=8) df = pd.DataFrame(np.random.randn(8,5),index=dates,columns = list("ABCDE")) print dfif __name__ == '__main__': main()
结果如下:
D:\Anaconda2\python/' target='_blank'>python.exe E:/pypractice/DataAnalysis/pandasTest.py<class 'pandas.core.series.Series'>0 21 42 63 84 105 126 147 168 189 20dtype: int64 A B C D E2017-03-01 -0.746429 -0.540836 1.884101 0.607853 -0.3677072017-03-02 1.172848 -0.482583 0.175146 -0.181268 -1.3044752017-03-03 -0.416664 1.784968 1.767710 -1.157681 -0.9097442017-03-04 -0.830197 -0.282451 0.543764 0.900877 0.5536312017-03-05 -0.614170 -0.371306 0.553044 -0.054903 1.3222862017-03-06 0.276449 -0.815241 -0.687530 0.514781 -0.8239632017-03-07 0.939306 0.494661 -0.342454 -0.125811 -1.5559092017-03-08 0.204852 0.006475 -0.625082 1.012985 0.447710Process finished with exit code 0
以上这篇浅谈Python的dataframe与series的创建方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
(责任编辑:admin)