Last active
January 28, 2021 07:25
-
-
Save aurora1625/b1b58867fdbb4f085012e459937f9daf to your computer and use it in GitHub Desktop.
pandas snippet 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you want to filter rows by a certain number of columns with null values, you may use this: | |
df.iloc[df[(df.isnull().sum(axis=1) >= qty_of_nuls)].index] | |
# update each value in column while iterating over the dataframe row by row | |
for index_label, row_series in df.iterrows(): | |
# For each row update the 'Bonus' value to it's double | |
df.at[index_label, 'Bonus'] = row_series['Bonus'] * 2 | |
# select column by multiple range | |
df_10_2_rank.iloc[:, np.r_[0,16:31]] | |
# select row by list length | |
df_single = df_multiple[df_multiple['Sub Indicator'].map(len)==1] | |
# group dataframe rows into list in pandas groupby | |
# single row | |
df.groupby('a')['b'].apply(list) | |
# multiple rows, need to select out the rows want to group | |
df.groupby('a').agg(list) | |
df.groupby('a').agg(pd.Series.tolist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment