I have a regex that parses US phone numbers into 3 strings. it works perfectly on the numbers: Now I need to add an additional regex to generate a Value Error for numbers such as I tried but non rejects the string in question I will greatly appreciate any ideas. I am very new to Regex! Answer In Python re
Converting Geojson information to geopandas geometry
I have geojson file like this: I would like to extract the polygon information and save as polygon geometry in a geopandas data frame. I’m having trouble converting extracting this information from the geojson I would appreciate if anyone can help Answer you can construct valid geojson from you dict sni…
a bug for tf.keras.layers.TextVectorization when built from saved configs and weights
I have tried writing a python program to save tf.keras.layers.TextVectorization to disk and load it with the answer of How to save TextVectorization to disk in tensorflow?. The TextVectorization layer built from saved configs outputs a vector with wrong length when the arg output_sequence_length is not None a…
Cache only a single step in sklearn’s Pipeline
I want to use UMAP in my sklearn’s Pipeline, and I would like to cache that step to speed things up. However, since I have custom Transformer, the suggested method doesn’t work. Example code: If you run this, you will get a PicklingError, saying it cannot pickle the custom transformer. But I only …
What is meaning of separate ‘bias’ weights stored in Keras model?
Post-edit: Turns out I got confused while constantly playing with the three functions below. model.layer(i).get_weights() returns two separate arrays (without any tags) which are kernel and bias if bias exists in the model. model.get_weights() directly returns all the weights without any tags. model.weights r…
Count the total number of multiple distinct occurrences in the same data frame
Suppose we have the data frame df I know that to count the number of ‘B’ I have to use (df == ‘B’).sum().sum(). Now suppose that I want to count how many elements contained in the list v = [‘B’, ‘C’] there are in the data frame. What could be a way of doing this…
Using rstrip() and lstrip() to remove 1st and last underscore character “_” withinin a string leads to a loss of character “t” in Python 3.7
I have a series of .txt file and I want to remove the prefix and suffix to make them easier to read (and do further analysis) A dummy name would be something like “Test_abcdef_000001.txt”, “Test_abcdef_000002.txt” or “Test_abcdeft_000001.txt” To remove the “Test_̶…
How do I do a groupby in python to split between orders?
I have a dataframe that shows order listing. How do I use it to find the number of orders that contain spicy food? Using this code gives me 2 Yes and 2 No, but it should actually be 2 Yes and 1 No as order 1001 is duplicated. Thank you. I would like to get an output that shows the
Group by calculation pandas
I have a dataframe after applying groupby: On this, I want to add a new column with the calculation: 10 / (no of items per category). For the example data, this would be: How can this be done? Answer Use Series.value_counts with Series.map: Or:
conda prefix (-p) still create a .conda directory on home
I’m using conda prefix to specify the directory to create my conda environment since my home directory has a small storage quota. But I noticed that conda still creating a .conda directory in my home directory which is quite large. I’m running the following command. The .conda dir in my home direc…