我创建了以下系列和数据帧:
import pandas as pd
Series_1 = pd.Series({'Name': 'Adam','Item': 'Sweet','Cost': 1})
Series_2 = pd.Series({'Name': 'Bob','Item': 'Candy','Cost': 2})
Series_3 = pd.Series({'Name': 'Cathy','Item': 'Chocolate','Cost': 3})`
df = pd.DataFrame([Series_1,Series_2,Series_3], index=['Store 1', 'Store 2', 'Store 3'])
我只想显示/打印出 DataFrame 中的一列(带或不带标题行):
任何一个
Adam
Bob
Cathy
或者:
Sweet
Candy
Chocolate
我尝试了以下代码但不起作用:
print(df['Item'])
print(df.loc['Store 1'])
print(df.loc['Store 1','Item'])
print(df.loc['Store 1','Name'])
print(df.loc[:,'Item'])
print(df.iloc[0])
我可以用一行简单的代码来完成吗?
最佳答案
通过使用 to_string
print(df.Name.to_string(index=False))
Adam
Bob
Cathy
关于python-2.7 - 显示/打印 Pandas 系列 DataFrame 中的一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46122910/