【发布时间】:2020-08-16 05:10:35
【问题描述】:
行和列是否本质上与数据对象相同?例如,在下面:
import pandas as pd
df = pd.DataFrame([
{"Title": "Titanic", "ReleaseYear": 1997, "Director": "James Cameron"},
{"Title": "Spider-Man", "ReleaseYear": 2002, "Director": "Sam Raimi"}
]
title_column = df['Title']
print(title_column)
print (type(title_column))
row_one = df.loc[0]
print(row_one)
print (type(row_one))
它们都返回 Series,其中 Column 以 0 为索引,而 Row 以 Column 为索引:
0 Titanic
1 Spider-Man
Name: Title, dtype: object
<class 'pandas.core.series.Series'>
Title Titanic
ReleaseYear 1997
Director James Cameron
Name: 0, dtype: object
<class 'pandas.core.series.Series'>
然后,一旦选择了多个列或行,它就会变成DataFrame。 Row 和 Column 基本上是同一类型的对象,或者它们之间有什么区别,在使用方式上?
【问题讨论】:
-
Are the Row and Column basically the same type of object- 我认为是的,第二个子问题可能更清楚?