您现在的位置是:课程教程文章

Pandas中创建Series方法有哪些?

2023-12-14 22:52课程教程文章 人已围观

在python的Pandas库中,作为其中一个数据结构的Series,虽然是一维的,但能够存储不同类型的数据,本文介绍Pandas中创建Series的三种方法:1、使用一个列表生成一个Series;2、使用一个字典生成Series,其中字典的键,就是索引;3、使用数组生成一个Series。

1、使用一个列表生成一个Series

myList = ['a', 'b', 'c', 'd']     # 创建一个列表
s1 = pd.Series(data = myList)
print(s1)
--------------------------------
输出:
0    a
1    b
2    c
3    d
dtype: object

2、使用一个字典生成Series,其中字典的键,就是索引

dictionary1 = {"name": "nick", "age": 12, "sex": "male"}

s5 = pd.Series(dictionary1)
print(s5)

3、使用数组生成一个Series

import numpy as np
arrySer=pd.Series(np.arange(10,15),index=['a','b','c','d','e'])
print(arrySer)

以上就在python的Pandas库中创建Series的三种方法,大家选择其中一种方法使用就可以啦~

课程教程:Pandas中创建Series方法有哪些?

上一篇:java中lock有哪几种用法

下一篇:没有了

站点信息

  • 文章统计篇文章