pandas系列和单列DataFrame有什么区别? [英] What is the difference between a pandas Series and a single-column DataFrame?

查看:255
本文介绍了pandas系列和单列DataFrame有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么熊猫区分Series和单列DataFrame?
换句话说:Series类存在的原因是什么?

Why does pandas make a distinction between a Series and a single-column DataFrame?
In other words: what is the reason of existence of the Series class?

我主要使用带有datetime索引的时间序列,也许这有助于设置上下文.

I'm mainly using time series with datetime index, maybe that helps to set the context.

推荐答案

引用

pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)

带有标注轴(行和列)的二维大小可变的,可能是异构的表格数据结构.算术运算在行和列标签上均对齐. 可以看作是Series对象的类似dict的容器.主要的熊猫数据结构.

Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a dict-like container for Series objects. The primary pandas data structure.

因此,系列是DataFrame 的单个列的数据结构,不仅在概念上,而且从字面意义上讲,即DataFrame中的数据实际上都作为一个存储在内存中. Series的集合.

So, the Series is the data structure for a single column of a DataFrame, not only conceptually, but literally, i.e. the data in a DataFrame is actually stored in memory as a collection of Series.

类似地:我们需要列表和矩阵,因为矩阵是用列表构建的.没有它们组成的列表,单行矩阵虽然在功能上等同于列表,但仍然不存在.

它们都具有极其相似的API,但是您会发现DataFrame方法始终可以满足您拥有多列的可能性.而且,当然,您总是可以向DataFrame添加另一个Series(或等效对象),而向另一个Series添加Series涉及创建DataFrame.

They both have extremely similar APIs, but you'll find that DataFrame methods always cater to the possibility that you have more than one column. And, of course, you can always add another Series (or equivalent object) to a DataFrame, while adding a Series to another Series involves creating a DataFrame.

这篇关于pandas系列和单列DataFrame有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆