简体   繁体   English

无法使用行索引从python数据框中获取行

[英]can not get rows from python dataframe using row index

i read data from csv to python dataframe, and set index_col to create multilevel index, here is the result: 我从csv读取数据到python数据帧,并设置index_col以创建多级索引,这是结果:

import pandas as pd
import numpy as np

path1= "C:\\Users\\IBM_ADMIN\\Desktop\\ml-1m\\ZTXDMEMPEE.csv"
frame1 = pd.read_csv(path1,encoding='utf8',index_col=['MGR_CNUM','CNUM'])
frame1

在此处输入图片说明

when i use method 'ix' to get rows using row index, i get incorrect result, 当我使用方法“ ix”使用行索引获取行时,我得到了不正确的结果,

frame1.ix['002263796']

在此处输入图片说明

First off. 首先。 Absolutely do not use .ix for anything other than mixed label and integer location selection. 绝对不要将.ix用于混合标签和整数位置选择以外的任何操作。 Choose iloc or loc . 选择ilocloc Your result appears to be correct as indexing selection works by choosing all the rows that have that index. 您的结果似乎是正确的,因为通过选择具有该索引的所有行来进行索引选择。 In this case, the outer level index. 在这种情况下,外部级别索引。

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

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