多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ***** ## 1.2. DataFrame 与 Series dataframe是二维结构化数据,series是一维数据。 dataframe有一个或者多个series组成,dataframe的一行或者一列就是一个series。 ### 1.2.1. Series的创建 **Series是能够存储任意数据类型的一维标签数组** ``` # 根据字典创建series a = {"name":"xiaoming","age":18,"sex":"male"} pd.Series(a,name='dict') ``` ![](https://img.kancloud.cn/b2/e2/b2e2f141a28064270ea0683bb356195a_311x88.png) ``` # From scala pd.Series(5,index=list("abcdef")) ``` ![](https://img.kancloud.cn/9d/a5/9da59fe396f508a15e0f7d9c05a7978c_186x146.png) ``` #根据列表创建series s1 b = [1,2,3,4,5,6] s1 = pd.Series(b,index = list("abcdef")) ``` series的values属性和index属性 ![](https://img.kancloud.cn/b7/83/b7834681561148f67f5e9f858d9101c0_195x154.png) ![](https://img.kancloud.cn/3a/50/3a5029d95f254232932174cbb6c8f525_535x179.png) ### 1.2.2. DataFrame的创建 DataFrame中的任意一行或一列用type()都可知类型是series ``` #根据字典创建series a = {"name":["xiaoming","xiaohong","xiaogang"],"age":[12,13,14]} pd.DataFrame(data = a,index = list('abc')) ``` ![](https://img.kancloud.cn/13/e8/13e8f340cadafa19a770cf4688e3f25e_184x137.png) ``` b = [ [1,2,3,4], ['a','b','c','d'] ] #根据二维数组创建series,abcd是列名,ab是索引 pd.DataFrame(b,columns=list("ABCD"),index= list('ab')) ``` ![](https://img.kancloud.cn/00/81/00813cc8bcadebf7d1f6a4404bc29a3d_151x113.png) ``` a = {"name":"xiaoming","age":18,"sex":"male"} s1 = pd.Series(a) df_ = pd.DataFrame(s1,columns = ['Values']) df_ ``` ![](https://img.kancloud.cn/90/30/903002254ab3e93d4509b178915429e5_140x153.png) ![](https://img.kancloud.cn/96/5e/965e53f4e1963e6d96cb490403dcfcc5_424x185.png)