繁体   English   中英

Python Dataframe错误切片

[英]Python Dataframe wrong slicing

嗨,我的代码如下所示:

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”值两者? 我尝试了不同的方法,但到目前为止没有任何效果

您将要使用.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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM