1.1 通过列表创建 代码如下(示例): In [22]:import pandas as pd In [23]:pd.Series([1,2,31,12,3,4]) Out[23]: 0 1 1 2 2 31 3 12 4 3 5 4 dtype: int64 In [24]:t = pd.Series([1,2,31,12,3,4]) In [25]:type(t) Out[25]: pandas.core.series.Series In [26]:t Ou...
Series是一种类似于一维数组的对象,由下面两个部分组成: values:一组数据(ndarray类型) index:相关的数据索引标签 1、Series的创建 两种创建方式 1.1 由列表或numpy数组创建 默认索引为0到N-1的整数型索引 #使用列表创建Series s1=Series(data=[1,2,3,4,5]) s1 1. 2. 3. type(s1) 结果为: pandas.cor...
import numpy as np import pandas as pd s=pd.Series(np.random.rand(5)) print(s) print("- - - - - -") print(s[2],"\t",type(s[2]),"\t",s[2].dtype) print("- - - - - -") print(float(s[2]),"\t",type(float(s[2]))) print(s[-1]) 标签索引 方法类似下标索引,...
File"C:\Users\Administrator PycharmPro jects\Python test \venv\lib\site-packages \pandas\core\series. py”,line 1311, in_ set_ 1abelsraiseValueError("%s not contained in the index” % str (key [mask]))ValueError: [’ f'] not contained in the index#出现报错,所以这样行不通# 还能通过...
本节我们主要介绍pandas对象series和dataframe当中的一些重要的方法 reindex方法 reindex方法会根据index对series和dataframe进行重排序,对于找不到的index会用NAN值进行填充。 In [151]: obj Out[151]: d 4.5 b 7.
索引对象Index Series和DataFrame中的索引都是Index对象示例代码: print(type(ser_obj.index)) print(type(df_obj2.index)) print(df_obj2.index) 运行结果: <class 'pandas.indexes.range.Ra...
1、导入pandas库 import pandas as pd 2、导入数据 data={"name":["小强","校长","小王","小李"],"age":["22","24","26","28"]}df=pd.DataFrame(data)3、运行一下 print(df)4、结果如下:name age0 小强 221 校长 242 小王 263 小李 28 5、输入索引 print(df.index)6、运行结果如下:Ran...
pandas.core.series.Series 2. DataFrame DataFrame是一个表格型的数据结构 每列可以是不同的值类型(数值、字符串、布尔值等) 既有行索引index,也有列索引columns 可以被看做由Series组成的字典 创建dataframe最常用的方法,见02节读取纯文本文件、excel、mysql数据库 2.1 根据多个字典序列创建dataframe In [17]: 代...
在上文【字段选取】一小节中,我们使用了选取一个字段的代码DATA['公司中文名称'],笔者在注释中有提到,使用这样的代码选取的数据字段为一维 Series 类型,在上上一期介绍 Pandas 数据类型的文章中>>>Python 教学 | 数据处理必备工具之 Pandas(基础篇),我们已经介绍过 Series 类型,这是一种具有索引的一维数据类型,...