Python Dataframe错误切片

时间:2017-11-19 20:50:59

标签: python pandas dataframe

您好我的代码如下:

data = pd.read_csv('people_wiki.csv')
obama = data.loc[data['name'].str.strip() == 'Barack Obama']
print(str(obama['text']))

我的输出是:

35817    barack hussein obama ii brk husen bm born augu...
Name: text, dtype: object

我不知道为什么我会看到这个35817 - 这是我的数据中的索引以及“名称”,“dtype”值?我尝试了不同的方法但到目前为止没有任何工作

1 个答案:

答案 0 :(得分:-1)

您希望使用.values来获取单元格内容:

data = pd.read_csv('people_wiki.csv')
obama = data.loc[data['name'].str.strip() == 'Barack Obama']

# This will give you a list of the cell contents for all of the matches:
# one match: ['example cell content']
# two matches: ['example cell content 1', 'example cell content 2']
print(obama['text'].values)

# You'll just need to specify which you want to use as a string
print(obama['text'].values[0]
相关问题