如何从熊猫中删除行而不提及索引值,因为我有重复的索引值

时间:2019-12-25 05:09:38

标签: python pandas dataframe

我有2个具有相同索引值的行,我需要基于column ['year']值删除一行,到目前为止,该值应等于2018。 不会一直到2018年,因此我需要根据另一个查询的输出自动更新它……有人可以帮我解决这个问题吗
“ vHe2”列<= 0的查询的输出
output of a query in which 'vHe2' column <=0


当使用索引号删除时,发现重复的索引值
when checked with index number to drop, found duplicate index values

1 个答案:

答案 0 :(得分:0)

您可以这样做:

Sub Macro12()
    Dim Cell As Range
    Dim Cell2 As Range

    For Each Cell In Range("D2:D25")
        ' If (Cell.Value >= DateValue("1 / 5 / 2019")) And (Cell.Value <= DateValue("30 / 4 / 2020")) Then
        If (Cell.Value >= 43586) And (Cell.Value <= 43951) Then
            For Each Cell2 In Range("C2:C25")
                If Cell2.Value = "2020-21" Then
                    Range("I3").Value = Cell2.Value
                    Range("J3").Value = Range("J3").Value + Cell2.Offset(0, 5).Value
                Else
                    Range("I4").Value = "other years"
                    Range("J4").Value = Range("J4").Value + Cell2.Offset(0, 5).Value
                End If
            Next Cell2
            ' ElseIf (Cell.Value >= DateValue("1 / 5 / 2021")) And (Cell.Value <= DateValue("30 / 4 / 2022")) Then
        ElseIf (Cell.Value >= 43599) And (Cell.Value <= 43599) Then
            Range("M3").Value = "step 1 clear"
        End If
    Next Cell
End Sub