My personal python code snippets and tips.
python3 -m pdb -c continue Rozpis.py -p Bik 2024-06.xls
import pandas as pd pd.isna(pd.NA) # True pd.isna(np.nan) # True
isnull is the same, it was original function, but due to NumPy isna, it was renamed and stayed as an alias.
df.drop_duplicates(subset=['col'], keep='last')
It does not aggregate. To get max or mean:
df.groupby('col', as_index=False).agg({'value': 'max'})
df.groupby('col', as_index=False).agg(['mean','max'])
import subprocess cmd = ["command", "arguments"] result = subprocess.run(cmd, capture_output=True, text=True, check=True)
import argparse
parser = argparse.ArgumentParser(
prog = "Program name"
description = "program description"
epilog = "text at the end of help page"
)
parser.add_argument("filename")
parser.add_argument("-i", "--interactive", action="store_true", help="argument description")
parser.add_argument("-o", "--output", type=str, help="argument description")
args = parser.parse_args()
Style checkers, similar.
flake8 . black .
can do similar.
Check for common programming mistakes, import order etc.
pylint .
uv run mypy *.py uv run mypy dir/