import numpy as np
import pandas as pd
# =====pandas数据结构:1、Series对象;2、DataFarme对象======
# =========创建一个Series对象==========
# 参数data:可以是任意数据对象,比如:字典、列表、numpy数组,(不能为空)
# 参数index:是对data的索引值,类似字典的key,(可省略)
# my_series = pd.Series(data, index)
countries = ['USA', 'Nigeria', 'France', 'Ghaha']
my_data = [100, 200, 300, 400]
my_series_01 = pd.Series(my_data, countries)
#print(my_series_01)
my_series_02 = pd.Series(my_data)
#print(my_series_02)
my_data_02 = {'a':50, 'b':60, 'c':70, 'd':80}
my_series_03 = pd.Series(my_data_02)
#print(my_series_03)
# ===========从Series中获取数据==============
# 访问Series中的数据类似与Python中字典
series_data_01 = my_series_01['USA']
#series_data_01 = my_series_01['Nigeria']
#series_data_01 = my_series_01['France']
#series_data_01 = my_series_01['Ghaha']
#print(series_data_01)
series_data_02 = my_series_02[0]
#series_data_02 = my_series_02[1]
#series_data_02 = my_series_02[2]
#series_data_02 = my_series_02[3]
#print(series_data_02)
series_data_03 = my_series_03['a']
#series_data_03 = my_series_03['b']
#series_data_03 = my_series_03['c']
#series_data_03 = my_series_03['d']
#print(series_data_03)
# ==========对Series进行算数运算操作===========
# 对 Series 的算数运算都是基于 index 进行的,如果 Pandas 在两个 Series 里找不到相同的 index,对应的位置就返回一个空值 NaN。
#jisuan_01 = m
pandas之DataFrame与Series实例详解
最新推荐文章于 2024-05-28 17:32:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)