Pandas – convert from dataframe append to concat.

the latest Pandas gives warning about append being depreciated. FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.   The main difference is that concat expects an iterable list. monnth_df = pd.concat( [ month_df,obs1 ], ignore_index=True) # month_df = month_df.append(obs1, ignore_index=True)  

Python – how to construct SQL with “AND” and “OR” with LIKE

def run_query_table_multi( search, and_flag=False ): if and_flag is True: combo = ” and ” else: combo = ” or ” try: conn = mariadb.connect( user=self.user, password=self.password, host=self.host, port=self.port, database=self.database ) except mariadb.Error as e: print(f”Error connecting to MariaDB Platform: {e}”, e) sys.exit(1) # Get Cursor cur = conn.cursor() my_sql_qry = “SELECT rec_id, title, http from recipe where” q_bld = “” […]

Python3 – strip html tags from string

Here is a code snippet to strip tags and leading and trailing whitespace   def remove_html_tags text): “””Remove html tags from a string””” clean = re.compile(‘<.*?>’) ntxt = re.sub(clean, ”, text ) return ntxt.strip()  

Numpy – array of strings.

Numpy supports strings and array of strings.   It is fixed length. If you replace an array element with a longer string it truncates it to fit. Each python character is 4 bytes ( unicode ). So a 40 character element in the array is 160 bytes. See example from Notebook below.

Pandas – how to edit columns for html table

How to edit table so that index and column names are on the same row. import beatifulsoup. from bs4 import BeautifulSoup find the empty tags in ‘thead’ and then fill with col names from the dataframe. Note: If you code “header=False”, the default style for table row will be gone <tr style=”text-align: right;”> html_doc = tide_table.to_html(header=False) soup = BeautifulSoup(html_doc, ‘html.parser’) […]

Windows – how to start Jupyter notebook without anaconda

So, you pip installed Jupyter.  Thinking – hey don’t have to start up Anaconda environment to run it. C:\Users\jonallen\Documents\github\weather_obs>pip install jupyter Collecting jupyter Downloading jupyter-1.0.0-py2.py3-none-any.whl (2.7 kB) Collecting ipywidgets Downloading ipywidgets-7.6.3-py2.py3-none-any.whl (121 kB) |████████████████████████████████| 121 kB 3.3 MB/s Collecting notebook Downloading notebook-6.4.3-py3-none-any.whl (9.9 MB) |████████████████████████████████| 9.9 MB 234 kB/s Collecting jupyter-console Downloading jupyter_console-6.4.0-py3-none-any.whl (22 kB) Collecting nbconvert Downloading nbconvert-6.1.0-py3-none-any.whl (551 […]

Using Pandas append on groups of CSV files

This function loads a series of daily csv files and combines them into a monthly dataframe  Create an empty Pandas DataFrame  append to empty DataFrame after each load. Word of caution – the columns must be the same for all inputs. One should test the columns to make sure you get what you expect. def load_monthly_noaa_csv_files( dir, noaa_station, ext = […]