Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数据帧行的访问索引_Python_Pandas_Dataframe - Fatal编程技术网

Python 数据帧行的访问索引

Python 数据帧行的访问索引,python,pandas,dataframe,Python,Pandas,Dataframe,我想删除列id,并创建了两个数据帧,一个是唯一的行,另一个包含重复的行。 下面是我的代码,我想要的是将列id添加到每个数据帧(join) 通过删除id并通过测试重复项,通过以下方式过滤原始数据: 然后对于反向遮罩,使用~: dfUNIC= df[~m] print (dfUNIC) id x1 x2 x3 x4 0 i1 13 10 12 24 2 i3 61 13 2 9 3 i4 61 13 22 12 通过删除id并通过测试重复项,通过以下

我想删除列id,并创建了两个数据帧,一个是唯一的行,另一个包含重复的行。 下面是我的代码,我想要的是将列id添加到每个数据帧(join)


通过
删除
id
并通过测试重复项,通过以下方式过滤原始数据:

然后对于反向遮罩,使用
~

dfUNIC= df[~m]
print (dfUNIC)
   id  x1  x2  x3  x4
0  i1  13  10  12  24
2  i3  61  13   2   9
3  i4  61  13  22  12

通过
删除
id
并通过测试重复项,通过以下方式过滤原始数据:

然后对于反向遮罩,使用
~

dfUNIC= df[~m]
print (dfUNIC)
   id  x1  x2  x3  x4
0  i1  13  10  12  24
2  i3  61  13   2   9
3  i4  61  13  22  12

我会做
cumcount

s=df.groupby(list(set(df)-{'id'})).cumcount()
df1=df[s==0].copy()
df2=df.drop(df1.index)
df1
Out[113]: 
   id  x1  x2  x3  x4
0  i1  13  10  12  24
2  i3  61  13   2   9
3  i4  61  13  22  12
df2
Out[114]: 
   id  x1  x2  x3  x4
1  i2  13  10  12  24
4  i5  61  13   2   9

我会做
cumcount

s=df.groupby(list(set(df)-{'id'})).cumcount()
df1=df[s==0].copy()
df2=df.drop(df1.index)
df1
Out[113]: 
   id  x1  x2  x3  x4
0  i1  13  10  12  24
2  i3  61  13   2   9
3  i4  61  13  22  12
df2
Out[114]: 
   id  x1  x2  x3  x4
1  i2  13  10  12  24
4  i5  61  13   2   9

你能说明预期结果吗?你能说明预期结果吗?