美文网首页
pandas 选取一列并使其保持dataframe格式

pandas 选取一列并使其保持dataframe格式

作者: WooWoods | 来源:发表于2018-12-11 09:55 被阅读10次
In [10]: df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B'])

In [11]: df
Out[11]:
   A  B
0  1  2
1  3  4

In [12]: df[['A']]

In [13]: df[[0]]

In [14]: df.loc[:, ['A']]

In [15]: df.iloc[:, [0]]

Out[12-15]:  # they all return the same thing:
   A
0  1
1  3

相关文章

网友评论

      本文标题:pandas 选取一列并使其保持dataframe格式

      本文链接:https://www.haomeiwen.com/subject/abxshqtx.html