Pandas Series 创建对象

举报
千江有水千江月 发表于 2020/12/29 13:25:47 2020/12/29
【摘要】 所属的课程名称及链接[AI基础课程--常用框架工具]环境信息* ModelArts  * Notebook - Multi-Engine 2.0 (python3)    * JupyterLab - Notebook - Conda-python3      * pandas 0.22.0Pandas 创建Series对象# list -> Seriesmy_list = [1,2,3,4...

所属的课程名称及链接

[AI基础课程--常用框架工具]


环境信息

  • * ModelArts
    •   * Notebook - Multi-Engine 2.0 (python3)
      •     * JupyterLab - Notebook - Conda-python3
        •       * pandas 0.22.0


Pandas 创建Series对象

# list -> Series
my_list = [1,2,3,4,np.nan,np.nan,7,8,9]
s_my_list = pd.Series(my_list)
print("s_my_list",s_my_list)

# ndarray -> series
s_nda = pd.Series(np.array(['a','b',"",'c']))
print("\n s_nda",s_nda)

# dict -> series
# a是索引
s_dict = pd.Series({"a":0,"b":5,"c":5})
print("\n s_dict",s_dict)
s_my_list 0    1.0
1    2.0
2    3.0
3    4.0
4    NaN
5    NaN
6    7.0
7    8.0
8    9.0
dtype: float64

 s_nda 0    a
1    b
2     
3    c
dtype: object

 s_dict a    0
b    5
c    5
dtype: int64


help

help(pd.Series)

Help on class Series in module pandas.core.series:

class Series(pandas.core.base.IndexOpsMixin, pandas.core.generic.NDFrame)
 |  One-dimensional ndarray with axis labels (including time series).
 |  
 |  Labels need not be unique but must be a hashable type. The object
 |  supports both integer- and label-based indexing and provides a host of
 |  methods for performing operations involving the index. Statistical
 |  methods from ndarray have been overridden to automatically exclude
 |  missing data (currently represented as NaN).
 |  
 |  Operations between Series (+, -, /, *, **) align values based on their
 |  associated index values-- they need not be the same length. The result
 |  index will be the sorted union of the two indexes.
 |  
 |  Parameters
 |  ----------
 |  data : array-like, dict, or scalar value
 |      Contains data stored in Series
 |  index : array-like or Index (1d)
 |      Values must be hashable and have the same length as `data`.
 |      Non-unique index values are allowed. Will default to
 |      RangeIndex(len(data)) if not provided. If both a dict and index
 |      sequence are used, the index will override the keys found in the
 |      dict.
 |  dtype : numpy.dtype or None
 |      If None, dtype will be inferred
 |  copy : boolean, default False
 |      Copy input data

......


备注

1. 感谢老师的教学与课件  
2. 欢迎各位同学一起来交流学习心得^_^  
3. 沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。  


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。