Stacking loc to filter a Python Pandas dataframe? Order can matter:
Filtering rows in a Python Pandas data frame? Use .loc: pd.col refers to the previous line’s returned data frame. So we can stack them:
How much memory does a Python list use? sys.getsizeof will tell you, sort of: It reports the memory used by the list, but not its elements:
Want stderr in your Python program to go somewhere else? Use redirect_stderr in contextlib:
Writing a bunch to non-stdout in Python? You might want to use redirect_stdout from contextlib:
Want to print to stderr, not stdout, in a Python program? Use sys.stderr and the “file” kwarg: stdout and stderr often look identical in a terminal — but they aren’t!
Normally, “print” in Python writes to stdout. Write elsewhere with the “file” keyword argument:
Want stdout from your Python program to go elsewhere? Assign sys.stdout to a writeable file. (Don’t forget to keep the original around!) Better: print’s file kwarg.
After you import a Python module, its repr (printed representation) shows its name and the loaded file. But some modules don’t have files; they were “frozen” into Python. They have no __file__ attribute, and show “frozen” in their __loader__.
Once you import a Python module, a second import won’t reload it. That’s usually good. But what if you want to? (Common in development and debugging.) This forces the reload.