Import netCDF file to Pandas dataframe

The xarray library handles arbitrary-dimensional netCDF data, and retains metadata. Xarray provides a simple method of opening netCDF files, and converting them to pandas dataframes: import xarray as xr ds = xr.open_dataset(‘/path/to/netcdf’) df = ds.to_dataframe() This will create a dataframe with a multi-index with all of the dimensions in it. Unfortunately, Pandas doesn’t support arbitrary … Read more

Creating a nested dictionary from a flattened dictionary

Here is my take: def nest_dict(flat): result = {} for k, v in flat.items(): _nest_dict_rec(k, v, result) return result def _nest_dict_rec(k, v, out): k, *rest = k.split(‘_’, 1) if rest: _nest_dict_rec(rest[0], v, out.setdefault(k, {})) else: out[k] = v flat = {‘X_a_one’: 10, ‘X_a_two’: 20, ‘X_b_one’: 10, ‘X_b_two’: 20, ‘Y_a_one’: 10, ‘Y_a_two’: 20, ‘Y_b_one’: 10, ‘Y_b_two’: … Read more

Joblib UserWarning while trying to cache results

I don’t have an answer to the “why doesn’t this work?” portion of the question. However to simply ignore the warning you can use warnings.catch_warnings with warnings.simplefilter as seen here. import warnings with warnings.catch_warnings(): warnings.simplefilter(“ignore”) your_code() Obviously, I don’t recommend ignoring the warning unless you’re sure its harmless, but if you’re going to do it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)