在python中,在导入熊猫并使用print(Properties.head())之后,我能够获得表形式的属性。
label area equivalent_diameter centroid-0 centroid-1 centroid-2
0 1 6901 23.621337 10.023185 9.577597 9.209535
1 2 254 7.857391 22.000000 9.062992 5.889764
2 3 1251 13.368609 25.381295 7.811351 8.749001
3 4 1 1.240701 30.000000 0.000000 0.000000
4 5 4573 20.593691 37.957577 9.056855 8.852176我的问题是,如何从表中提取一个值,比方说,质心-0列和零行对应于10.023185。我怎么能只打印这个值?
发布于 2022-05-18 19:00:45
你可以从两方面着手
使用名称- .loc()
df.loc[0, 'centroid-0']或使用索引- .iloc()
df.iloc[0, 4]发布于 2022-05-18 19:11:49
TL;博士
df.loc[0, 'centroid-0'] # extract the 1st value of the column
df.loc[:, 'centroid-0'] # extract the whole column长答案您可以使用df.loc或df.iloc。如果您想使用df.iloc:
df.iloc[0, 3] # extract the 1st value of the column
df.iloc[:, 3] # extract the whole column主要的区别是df.iloc只对ids起作用。
https://stackoverflow.com/questions/72294573
复制相似问题