简体   繁体   English

pandas:删除与之前的原始数据具有相同列值的行

[英]pandas: delete a row having same value of a column as in previous raw

Here is my df:这是我的df:

data = { 'utime': [1461098442,1461098443,1461098443,1461098444,1461098445],
  'lat': [41.1790265,41.1791703,41.1791464,41.1791703,41.1791419],
  'lon': [-8.5951883,-8.5951229,-8.5951376,-8.5951229,-8.5951365]
}

df = pd.DataFrame(data)
df

       utime        lat        lon
0   1461098442  41.179026   -8.595188
1   1461098443  41.179170   -8.595123
2   1461098443  41.179146   -8.595138
3   1461098444  41.179170   -8.595123
4   1461098445  41.179142   -8.595137

Two samples are received at same time (unix epoch 1461098443 ) so I want retain 1, and delete the other.同时收到两个样本(unix epoch 1461098443 ),所以我想保留 1,删除另一个。

So that I have所以我有

       utime        lat        lon
0   1461098442  41.179026   -8.595188
1   1461098443  41.179170   -8.595123
3   1461098444  41.179170   -8.595123
4   1461098445  41.179142   -8.595137
df = df.groupby('utime', as_index=False).agg('first')
        utime        lat       lon
0  1461098442  41.179026 -8.595188
1  1461098443  41.179170 -8.595123
2  1461098444  41.179170 -8.595123
3  1461098445  41.179142 -8.595137

暂无
暂无

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

相关问题 Pandas DataFrame-删除特定列中与上一行具有相同值的行 - Pandas DataFrame - delete rows that have same value at a particular column as a previous row 如何使用前一行值以及同一行中其他列中的值来计算pandas中列的值 - how to use previous row value as well as values in other column in same row to compute value of a column in pandas Python Pandas Dataframe 根据同一列中的前一行值计算新行值 - Python Pandas Dataframe calculating new row value based on previous row value within same column 如何从熊猫数据框中获取同一行(上一列)的上一个值? - How to get the previous value of the same row (previous column) from the pandas dataframe? Pandas 列取决于其先前的值(行)? - Pandas column that depends on its previous value (row)? Pandas:如何使用其他 dataframe 的列值从 dataframe 返回具有相同行值的行? - Pandas: How to return the row from dataframe having same row values by using column value of other dataframe? 如果前一行等于某个值,则从 Pandas df 中删除一行 - Delete a row from a Pandas df if the previous row is equal to some value 用 Pandas 中的前一行列填充当前行和列值 - Fill current row and column value with previous row column in Pandas 替换同一列中上一行的值 - Replace value from previous row in same column 从Pandas列中的当前行值中减去前一行的值 - Subtract previous row value from the current row value in a Pandas column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM