I have this code:
Different_year = df[df['Start_year'] != (df['End_year'])]
And i just want to remove that condition from my main dataframe like this:
df.drop(['Different_year'])
Surprisingly it works but the dataframe still has the same shape
I have this code:
Different_year = df[df['Start_year'] != (df['End_year'])]
And i just want to remove that condition from my main dataframe like this:
df.drop(['Different_year'])
Surprisingly it works but the dataframe still has the same shape
The drop
method does not work in place unless you specify so.
df.drop(different_year, inplace=True)
or assign it
df = df.drop(different_year)
Make sure your variable different_year
are indices.
Below solutions should work. Notice the following for Method 1:
drop
.df
so the dataframe is actually modified.axis=0
represents index-level drop. More information in df.drop
documentation. Method 1
different_year = df[df['Start_year'] != (df['End_year'])].index
df = df.drop(different_year, axis=0)
Method 2
df = df[~(df['Start_year'] != (df['End_year']))]