One - One Code All

Blog Content

pandas的dataframe 获取某一值所在的行索引

Python 统计学-科学计算   2018-01-10 18:46:35

pandas dataframe 根据某个值获取其所在行索引

# 比如2012年所在的行索引
index = df[df.year == 2012].index.tolist()[0]  
print(index)  # 2
# 找到索引号为3月份的值
value = df.month.loc[3]
print(value)  # 4



上一篇:pandas的dataframe取最后一列,最后一行数据
下一篇:mac中python安装pandas时报错cannot install 'numpy',Cannot uninstall 'numpy'.

The minute you think of giving up, think of the reason why you held on so long.