Home > Enterprise >  How do I delete a row when two dataframes in pandas do not have the same length? - python
How do I delete a row when two dataframes in pandas do not have the same length? - python

Time:01-25

I have two dataframes in pandas:

df1 can have 365 or 366 rows

df2 has 366 rows

If df1 and df2 have the same number of rows I want to output "same row size". If, df1 and df2 don't have the same sizes I want to delete row 59 at df2.

all because of leap year :)

CodePudding user response:

Use:

if len(df1) != len(df2):
    df2 = df2.drop(59)

Another idea is remove row with 29. Feb, how do it depends of data.

  •  Tags:  
  • Related