簡體   English   中英

如何在Python中從DataFrame Pandas打印整數索引

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

我有兩個DataFrames(1)水果和(2)市場。 兩者都有三行,分別表示為0,1,2,只有一列沒有標題。

print fruit
0   apple
1   pear
2   melon

print market
0   apple
1   pear
2   melon

我想將索引打印為整數並在下面嘗試過,但是在

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')>

我該怎么做才能只打印不帶括號的0? 目標:0

這行得通嗎?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM