Storage space for my Python code that may or may not be in production.
import dateutil.parser
new_date = dateutil.parser.parse(string_date)
from pathlib import Path
file_path = Path(directory_var).joinpath(file_name_var)
dict.pop("name_of_key", None)
list2 = list(set(list1))
new_dict = {k: v for k, v in dict.items() if v is not None}
exec(open("python_script.py").read())
ord_char = chr(ord(orig_char))
import datetime
current_date = datetime.datetime.today()
import datetime
date_diff = dt_object2 - dt_object1
date_diff.days
result = max(string_list, key=len)
from pathlib import Path
in_file = Path(full_path_var).name
from pathlib import Path
in_file_no_ext = Path(full_path_var).stem
char_ord = ord(orig_char)
df1 = df1.append(df2, ignore_index=True, sort=False)
df = df.append(dictionary, ignore_index=True)
(df["column_name"].notnull()) &
(df["column_name"].str.contains("string"))
(df["column_name"].notnull()) &
(~df["column_name"].str.contains("string", na=False))
column_list = df["column"].tolist()
dict_list = df.to_dict("records")
df["column_name"] = ["".join(i) if isinstance(i, list) else i for i in df["column_name"]]
df["column_name"] = pd.to_numeric(df["column_name"], errors="coerce").astype(pd.Int64Dtype())
unique_values = df.groupby("column_name")["column_name"].count()
total_unique = df["column_name"].nunique()
df.loc[df["current_column"] == "CurrentColumnValue", "new_column"] = "NewColumnValue"
df.drop(["column1", "column2", etc.], axis=1, inplace=True)
df.drop_duplicates(keep="first", inplace=True)
df.drop_duplicates(["column1", "column2", "column3", etc.], keep="first", inplace=True)
df.dropna(axis=0, subset=["ColumnName"], inplace=True)
df1 = df.iloc[:, :X]
df["new_column"] = df["original_column"].str.replace("\d+", "", regex=True)
df["new_column"] = df["original_column"].str.extract("(\d+)", expand=False)
df = pd.DataFrame(columns=["column1", "column2", "column3", etc.])
df = df[["column1", "column2", etc.]]
new_df = pd.merge(df1, df2, how="outer",
left_on="df1_column", right_on="df2_column",
indicator=True)
df = pd.read_csv(filehandle, encoding="utf-8")
df = pd.read_csv(filehandle, sep="\t")
df = df.rename(columns={"OldColumnName1": "NewColumnName1", "OldColumnName2": "NewColumnName2", etc.})
df["column"] = df["column"].str.replace('\xb5', 'u')
df.fillna("", inplace=True)
df2 = df1.where(df1.notnull(), None)
df["new_column"] = df["original_column"].str.split("split character").str[0]
df["new_column"] = df["original_column"].str.split("split character").str[-1]
df["column_name"] = df["column_name"].str.strip("unwanted characters")
df.to_csv(filehandle, index=False)
df.to_csv(filehandle, sep="\t", index=False)
filehandle = open("filename", "w", newline="\n")
df.to_csv(filehandle, index=False)
import sys
df.to_csv(sys.stdout, index=False)
from importlib import reload
reload(module)
import re
new_string = re.sub("[^\d]", "", old_string)
new_list = list(set(old_list))
dictionary[new_key] = dictionary.pop(old_key)
exec(open("python script").read())
import random
from datetime import datetime
random.seed(datetime.now().timestamp())
import synapseclient
syn = synapseclient.Synapse()
syn.login(silent=True)
Synapse login (see above)
import synapseutils
syn_contents = synapseutils.walk(syn, folder_syn_id)
for __, __, filelist in syn_contents:
if len(filelist) > 0:
for __, syn_id in filelist: