Drop rows of pandas dataframe that don't have finite values in certain variable(s)
Date : March 29 2020, 07:55 AM
seems to work fine I cannot see what the built-in function is for the following simple but seemingly common/useful task: Drop rows which have no value for any of my key columns. adf = adf.dropna(subset=interestingVars, how='all')
|
python & pandas - Drop rows where column values are index values in another DataFrame
Tag : python , By : snapshooter
Date : March 29 2020, 07:55 AM
Hope this helps The Original DataFrame(df1) looks like: cols = ['NoDemande','NoUsager']
mask = df1[cols].isin(df2.reset_index()[cols].to_dict('list'))
df1[~mask.all(1)]
|
Drop or replace values within duplicate rows in pandas dataframe
Date : March 29 2020, 07:55 AM
I hope this helps you . df.loc[df.duplicated(subset=['B','C']), ['B','C']] = np.nan seems to work for me. Edited to include @ALollz and @macaw_9227 correction.
|
how to find rows with both positive and negative values in pandas dataframe
Tag : python , By : Matt Leacock
Date : March 29 2020, 07:55 AM
Hope that helps Edit 2: you may also use transform to avoid set_index/reset_index as follows: m = df.w_col.lt(0).groupby(df.word_col).transform('nunique').eq(2)
df.loc[m]
Out[2768]:
e_col in_col word_col w_col
0 31 9 algorithm -0.053538
4 30 8 algorithm 0.043637
m = df.w_col.lt(0).groupby(df.word_col).nunique().eq(2)
m = df.w_col.lt(0).groupby(df.word_col).unique().str.len().eq(2)
df.set_index('word_col').loc[m].reset_index()
Out[2738]:
word_col e_col in_col w_col
0 algorithm 31 9 -0.053538
1 algorithm 30 8 0.043637
|
Drop the rows which contains duplicate values in 2 columns in a pandas dataframe
Date : March 29 2020, 07:55 AM
wish of those help Use df.nunique() on axis=1 and filter out rows which return 1: df[~df.nunique(1).eq(1)]
A B
0 cat fish
2 cat fish
3 dog cat
|