loc和iloc的区别

import pandas as pd
import numpy as np
df = pd.DataFrame(np.arange(10).reshape(5,2),index=list("cvbnm"),columns=list('AB'))
print(df)
print("-----------------------------------------")
print(df.iloc[[2]])#iloc根据下标找元素
print("-----------------------------------------")
print(df.loc[["c"]])#loc根据行名找元素

  

 

posted @ 2020-03-16 21:15  胡辣汤王子  阅读(376)  评论(0编辑  收藏  举报