I want to find out if a substring is contained in the string and remove it from it without touching the rest of the string. The thing is that the substring pattern that I have to perform the search on is not exactly what will be contained in the string. In particular the problem is due to spanish accent vocal…
Tag: python
“TypeError: shield() got an unexpected keyword argument ‘loop'” when running discord.py bot
When I launch my discord.py bot with this code: I get this error: Does anyone have any idea why I have this error? I have already removed everything that is not required in the code and I have updated all my pip freeze, but the error doesn’t change. Answer This is usually caused because of outdated aioh…
With pandas.DataFrame.replace in python how to replace all ä with ae?
With pandas.DataFrame.replace in python how to replace all ä with ae only the ones that are in between ${}? Below is my Python code that I tried with but it didn’t worked: df.replace({‘Desc’: r’${.*ä}’} , {‘Desc’: r’${.*ae}’}, regex=True) As a first e.g. A…
check if numeric element is in an interval key dictionary in python
from the following dictionary with tuple as keys and a string as value: by using the dict, how would be possible to use a function with the following behaviour? gives the following output: Answer If you expect age to be within multiple intervals and you want to get them all: I have added an overlapping interv…
DateTime format in python from Postgres queries
I have a below result from postgres query performing in python. How can parse or format so I get date along with time only ? Answer Problem is solved by using result[0][0] in pyhton code
np.where for 2d array, manipulate whole rows
I want to rebuild the following logic with numpy broadcasting function such as np.where: From a 2d array check per row if the first element satisfies a condition. If the condition is true then return the first three elements as a row, else the last three elements. A short MWE in form of a for-loop which I wan…
If you see valid patterns in the file then the issue is probably caused by a circular import in django
I am getting this error “If you see valid patterns in the file then the issue is probably caused by a circular import in”. I saw other stack flow questions and I know the error is coming from views.py but I cannot seem to figure out where the error is views.py/myapp urls.py/myapp urls.py/myproject…
Merge 2 columns from a single Dataframe in Pandas
I want to merge 2 columns of the same dataframe, but by using some specific condition. consider the following dataframe : number-first Number-second 1 Nan 2 4C 3A 5 Nan 6 Nan 7 Nan Nan The conditions are: If the Number-first column has a alphanumeric value and the Number-second Column has a Nan value or a …
Implementing a match counter into a lotto number guesser
im rather new to python and found someones lottery simulation in github. After playing around with it for a while i wanted to add a counter, that counts the number of matches of your Number out of the total draws. I don’t know if it is because i did not write the code myself, but i can’t seem to m…
Pandas/Geopandas Merge with a mask selection
I usually work with Arcpy but am trying to learn more pandas/geopandas uses. I have a mask applied to a csv table and a shapefile that I want to merge together in order to find matches between the two based on a specific field. However, when I try to merge them together, I get the error “The truth value…