I have an xlsx file containing too much data. however the data contains duplicate values in column named UniversalIDS which I wanted to replace it with a randomly generated IDS with Pandas. So far I’ve tried different scenarios which I googled but did not work. for example I tried this: also I tried oth…
Tag: python-3.x
Null/duplicate check in a column based on another column filter
I am working on pandas with the below requierment I need to check the below conditions if criteria is A, then m shouldn’t be null if criteria is B then n shouldn’t be null I wrote the below code for it or but both are not giving correct result I have also tried but this giving the columns without …
Merging two lists in a certain format in Python
I have two lists A and B. I am trying to merge the two lists into one in a specific format as shown in the expected output. I also show the current output. The current output is The expected output is Answer Or as @Mechanic Pig suggested in comments using list comprehension:
Capture substring and send it to a function that modifies it and can replace it in this string
Incorrect output that I am getting, because if I incorrectly capture the substrings, the replacements will also be incorrect Having well-defined limits, I don’t understand why this capture pattern try to capture beyond them? And the output that I need is that: Answer There are several errors in your cod…
Is it possible to change the attribute value in the enum?
I need to reassign the attribute value in Enum. I tried to reassign the attribute, but I got: AttributeError: cannot reassign member ‘number’ Answer Author’s note: This is a horrible idea. Let’s just delete the string “1” from Python and replace it with “2” You …
Using multipe operators in Python sequentially
I’m trying to understand how Python handles using multiple sequential operators to add and subtract numbers. Here is an example of what I mean: I don’t understand what decides whether to add or subtract these two integers. I’ve used Python 3.11.1 for this example. Answer To understand how th…
How can we parse a JSON file for specific records of county borders and overlay that on a Folium HeatMap?
I found a JSON file that has borders of US counties, right here. https://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_500k.json How can I parse that file for specific records, like ‘Durham’ and ‘Raleigh’ and ‘Charlotte’ together, and plot these on a Folium map?…
Add a character to a specific duplicate string
I’m trying to add a character to a specific duplicate string, like in the following situation: nomes_comp = [‘Fulano A’, ‘Beltrano B’, ‘Fulano A’] So I have duplicate items on my list; I would like to add another character in one of the duplicate items, hoping to get …
Looping through Python Dict and Normalising
I have multiple dict in a list and I want loop through each dict and flatten the file. When I run this code its giving me the ‘NoneType’ object is not subscriptable error. And the custom fields in the below json will be having many other fields as well Project_details list will be consisting of in…
Remove all elements in each list of a nested list, based on first nested list
I have a following list: I want to remove 0 in a[0] and corresponding values of a[1] and [2], so the result list should be as follows: Answer itertools.compress is built for this task. Pair it with a listcomp to operate on each sublist, and force it to eagerly produce each new sublist, and you get what you wa…