Last active
May 23, 2021 06:07
-
-
Save AayushSameerShah/045f593b99ba1cf07d50f632a7a26793 to your computer and use it in GitHub Desktop.
This gist presents various mini-time savers pandas snippets
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
# 1. Use of .agg in groupy | |
DF.groupby('').agg(['mean', 'max']) | |
# or | |
DF.groupby('').agg({'col1:': 'max', | |
'col2': 'min'}) | |
# 2. Amazing, when using agg from above or other, if | |
# you want to rename the columns ON THE AIR, then... | |
DF.groupby('').agg( | |
new_col_name1 = pd.NameAgg( 'old_col1', 'min'), | |
new_col_name2 = pd.NameAgg( 'old_col2', 'max') | |
) | |
# 3. Insert column at certain place | |
DF.incert(0, 'NAME', series) | |
# 4. Use where on series | |
DF.col.where(condition, this, else_this) | |
# 5. Check memory usage! | |
DF.memory_usage() | |
# deep | |
DF.memory_usage(deep= True) | |
# 6. Replace somathing! | |
DF.replace(replace_what, replace_with) | |
# or | |
DF.replace({replace_what1 : replace_with1, | |
replace_what2 : replace_with2}) | |
# 7. Conditional Formatting ! | |
DF.style.highlight_max(axis= 0, color= 'green') | |
# 8. Drop duplicates | |
DF.drop_duplicates(keep= 'first') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the Part
1
of the snippet series.