Python

Anti-Patterns Link to heading

Background tasks Link to heading

Dataclasses Link to heading

f-string Link to heading

debugging Link to heading

user = "eric_idle"
f"{user=}"
# "user='eric_idle'"
f"{user = }"
# "user = 'eric_idle'"

padding Link to heading

val = "test"
f"{val:>10}"
# '      test'
f"{val:<10}"
# 'test      '
f"{val:_<10}"
# 'test______'
f"{val:^10}"
# '   test   '

Fonte: https://fstring.help/

JSON Link to heading

  • cysimdjson - SIMDJSON is C++ JSON parser, reportedly the fastest JSON parser on the planet.
  • ijson - iterative JSON
  • orjson - fast, supports NumPy
  • rapidjson - RapidJSON is an extremely fast C++ JSON parser and serialization library
  • ujson - written in C with Python bindings

Keycloak Link to heading

pandas Link to heading

  • axios: 0=linha e 1=coluna
  • pandas-profilling - PyPI, docs

Geral Link to heading

df.shape  # (linhas, colunas)
df.info()
df.High.mean()  # média da coluna High
df.Date = pd.to_datetime(df.Date)  # convert column to datetime

Informações Estatísticas Link to heading

df.describe()  # informações estatísticas
df.ride_duration.std()  # desvio padrão da coluna ride_duration

Visualização Link to heading

df.High.plot()  # gráfico da coluna High
df.Volume.hist()  # histograma da coluna Volume
df.plot.scatter('c1', 'c2')  # gráfico de dispersão
df.Low.plot(kind='box')  # gráfico boxplot

Valores ausentes Link to heading

df.isnull().sum()  # conta o número de linhas com NaN
df.isnull().sum() / df.shape[0] # % de valores ausentes
df.dropna(subset=['user_gender'], axios=0)  # apaga as linhas com valor NaNs da coluna user_gender

Profiling Link to heading

ProfilerWhatGranularityHow
timeitrun timesnippet-level
cProfilerun timemethod-leveldeterministic
statprof.pyrun timemethod-levelstatictical
line_profilerrun timeline-leveldeterministic
memory_profilermemoryline-level+- deterministic
pymplermemorymethod-leveldeterministic

Fonte: https://www.youtube.com/watch?v=DUCMjsrYSrQ

String Parsing Link to heading

  • parse - Parse strings using a specification based on the Python format() syntax.
  • ttp - Template Text Parser