简体   繁体   English

如何在Python中从DataFrame Pandas打印整数索引

[英]How to print index in integers from DataFrame Pandas in Python

I have two DataFrames (1) fruit, and (2) market. 我有两个DataFrames(1)水果和(2)市场。 Both have three rows denoted 0,1,2 and only one column with no header. 两者都有三行,分别表示为0,1,2,只有一列没有标题。

print fruit
0   apple
1   pear
2   melon

print market
0   apple
1   pear
2   melon

I would like to to print the index in integers and tried below but have hard time in 我想将索引打印为整数并在下面尝试过,但是在

print market.iloc[np.where(fruit[0] == market)].index
Int64Index([0], dtype='int64')

print market.iloc[np.where(fruit[0] == market)].index.tolist
<bound method Int64Index.tolist of Int64Index([0], dtype='int64')>

print market.iloc[np.where(fruit[0] == market)].index.values
[0]

print market.iloc[np.where(fruit[0] == market)].index.get_values
<bound method Int64Index.get_values of Int64Index([0], dtype='int64')>

What should I do to print 0 only without the brackets? 我该怎么做才能只打印不带括号的0? Goal: 0 目标:0

Would this work? 这行得通吗?

print(list(market.index)[0])
print(list(fruit.index)[0])

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

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