今天小编就为大家分享一篇浅谈python的dataframe与series的创建方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
如下所示:
# -*- coding: utf-8 -*- import numpy as np import pandas as pd def 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 df if __name__ == '__main__': main()
结果如下:
D:Anaconda2python.exe E:/pypractice/DataAnalysis/pandasTest.py 0 2 1 4 2 6 3 8 4 10 5 12 6 14 7 16 8 18 9 20 dtype: int64 A B C D E 2017-03-01 -0.746429 -0.540836 1.884101 0.607853 -0.367707 2017-03-02 1.172848 -0.482583 0.175146 -0.181268 -1.304475 2017-03-03 -0.416664 1.784968 1.767710 -1.157681 -0.909744 2017-03-04 -0.830197 -0.282451 0.543764 0.900877 0.553631 2017-03-05 -0.614170 -0.371306 0.553044 -0.054903 1.322286 2017-03-06 0.276449 -0.815241 -0.687530 0.514781 -0.823963 2017-03-07 0.939306 0.494661 -0.342454 -0.125811 -1.555909 2017-03-08 0.204852 0.006475 -0.625082 1.012985 0.447710 Process finished with exit code 0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。