Pandas

Intro Getting started, User-guide, API refs. Install: pip install pandas or conda install -c conda-forge pandas Import: import pandas as pd Reading and Saving Files See official guide Reading Usepd.read_*(), which returns a DataFrame: csv df = pd.read_csv("xxx.csv") xslx df = pd.read_xslx("xxx.xslx") parquet: df = pd.read_parquet("xxx.parquet") Saving Use df.to_*(), where df is a DataFrame: Efficiency of files parquet > csv > xslx by efficiency parquet: df.to_parquet("xxxx.parquet") excel: df.to_excel("xxxx.xlsx", sheet_name="sheet1", index=False) Inspecting See official guide...

December 29, 2023 327 words 2 min

Logging and Debugging in Python

Rich: a Python library for rich text and beautiful formatting in the terminal Github, Documentation pip install rich Printing Console from rich.console import Console console = Console() # ======================================== # print auto formated objects # ======================================== console.log("Hello from", console, "!") # ======================================== # print local variable of current function # ======================================== def func(): local_val1 = 42 local_val2 = [4,2] console.log(func, log_locals=True) func() Inspect: Generate a report on an object: from rich import inspect inspect(inspect) # this also prints the usage of inspect Logging # Other library may handle logging, # remember to put this at top level....

December 29, 2023 334 words 2 min

Blog Notes

Notes of settings of my blog.

April 10, 2023 654 words 4 min