I have the below dataframe which comes from a JSON trying to format ready for db insertion, i am splitting using .tolist() but getting error for None entries. tried fillna and replace to insert a dummy list i.e. [0,0,0] but will only let me replace with a string. Any suggestions welcome. this works #df_split_batl = df_split_batl.fillna(‘xx’) #df_split_batl = df_split_batl.replace(‘xx’,’yy’) but
Tag: python
compare 2 string columns in data frame and add 1 to key if different
I’m having a hard time trying to figure this out, I have a data frame with multiple columns after merging 2. I have 2 list: I need to compare each group of variables and if they are different add 1 to the key column I was trying to use something like this: Answer I would avoid loops. Is there any
Machine Learning question (Solving ValueError: could not convert string to float:)
I am running the example code Below: How the CSV looks **-Using a csv with the name phishing_site_urls.csv, that has two columns one named “URL” and the other “Label”. Where the URL column holds links that are either phishy or valid and the label column has a corresponding “bad” or “good” for determining which link in the URL column is
HTMX websockets extension doesn’t connect to Django channels
I try to connect a Django channels Consumer to a HTMX ext-ws element, but I can’t get a step further. The HTMX.js and the ws.js gets loaded correctly at the client’s browser. If I use the old HTMX-builtin hx-ws method, at least the websocket connects. But I can’t get a message to the HTMX element (I thought the #message div
Selenium : Get text inside an element but not texts inside the nested tags within it
Lets say I have an element When I am fetching the element by classname This gives me What I wanted was just ₹199. Note that I can’t just format the text and get the first text on split by space as the structure of the page keeps changing. Answer Using little bit JS: Output: What we are doing with JS
Python logging: how to write logs into file and stdout
I have a main file where I use all the functions from the module. I want to log all the necessary things into file and into stdout. It works when I use logger.info(“Write it into file”) inside main file, but it doesn’t work when I import here some functions from the other scripts. I use it inside main file to
How to fill nested dict when you only have a list of key, value for the final layers?
I have a nested dict of the folling form: And a flat dict with only the values in the final layer: My expected output after filling the values in the first dict would be: How should I approach this? Answer I hope I’ve understood your question correctly. You can use recursion to replace the values of keys in-place: Prints:
How to print dict key value dynamically?
I’m trying to print a dict key value dynamically. EX: As we see the key ‘waninfo’ and ‘1’ are fixed and i would like to use the keys after dynamically, like this: How can i do this? Answer If there’s a constant number of keys, it might be easiest to just declare separate variables for them: If you have a
adding consequently items of a list to a dataframe
As a practice, I have created the following dataset of reading books: Then I added a fourth column as follows And now I would like to add as follows (I mean as rows 5 and 6) the following item, always by using the list I have tried adding other titles the following code which does not work: Since I am
Pandas TypeError: unhashable type: ‘list’ when importing from csv
I’m trying to clean some data from a csv file. Here’s an example of the data I’m importing. What I’m trying to do is split the cell by the first comma. The data before the comma goes to one column, the data after goes to another. I’ve set up a function to handle the data: The csv file is loaded