Error while installing through pip install psycopg2
looks like this:
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option (...)
Reference to the solution here.
import pandas as pd | |
# Create sample pandas.Series to calculate frequency | |
s = pd.Series(pd.date_range("2021", freq="18H", periods=1000)) | |
# Calculate frequency grouping by month | |
# If you want another period check following link: | |
# https://pandas.pydata.org/docs/user_guide/timeseries.html#timeseries-offset-aliases | |
freq_count = s.dt.to_period("M").value_counts(sort=False) |
import pandas as pd | |
# The function shows `str` for dates, but could be datetime.date objects as well | |
def n_date_intervals(start_date: str, end_date: str, intervals_count: int) -> pd.Series: | |
return pd.Series(pd.date_range(start_date, end_date, periods=intervals_count)) | |
# Change this variables as needed | |
start_date = "2018-01-01" | |
end_date = "2021-03-24" | |
intervals_count = 5 |
import pandas as pd | |
utc_now_pd = pd.Timestamp.utcnow() | |
# The function round(freq="D") is magic behind the round up | |
# Use replace(tzinfo=None) to remove timezone information | |
utc_now_ceil = utc_now_pd.round(freq="D").to_pydatetime().replace(tzinfo=None) | |
# Convert to ISO format | |
utc_now_str = utc_now_ceil.strftime("%Y-%m-%dT%H:%M:%S") |
-- You can count the rows to be equal to columns that you're checking | |
SELECT * | |
FROM information_schema.columns | |
WHERE table_schema = '<table_schema>' | |
AND table_name = '<table_name>' | |
AND column_name IN ('<column1>', '<column2>'); |
from functools import partial | |
def print_n_dict_elem(n, dictionary, elem): | |
print(n * dictionary[elem]) | |
# Create a new function that print elem 3 times | |
print_3_dict_elem = partial(print_n_dict_elem, n=3, dictionary={"a": "A", "b": "B"}) | |
print_3_dict_elem(elem="a") | |
# Update dictionary passed as an argument |
# Remember to install more_itertools first | |
# pip install more-itertools | |
from more_itertools import grouper | |
def do_something_with_iterable(iterable): | |
pass | |
n = 3 | |
chunks = grouper('a'*10, n) | |
for c in chunks: |
import pandas as pd | |
df = pd.DataFrame({"A": [0, 1, 0], "B": ["a", "b", "c"], "C": [1, 2, 3]}) | |
df.set_index(["A", "C"], drop=False, inplace=True) | |
result = {level: df.xs(level).to_dict("index") for level in df.index.levels[0]} | |
print(result[0]) |
Error while installing through pip install psycopg2
looks like this:
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option (...)
Reference to the solution here.
import pandas as pd | |
df = pd.concat([pd.read_csv(f, compression="gzip") for f in os.listdir() if f.endswith(".gz")], ignore_index=True) |
import pandas as pd | |
import numpy as np | |
df = pd.DataFrame({"A": [1, 2, 3], "B": [1.2, np.NaN, 3.4]}) | |
result = ( | |
df | |
.replace([np.nan], [None], regex=False) | |
.to_dict(orient="records") | |
) |