I have a FastAPI GET endpoint that is returning a large amount of JSON data (~160,000 rows and 45 columns). Unsurprisingly, it is extremely slow to return the data using json.dumps(). I am first reading the data from a file using json.loads() and filtering it per the inputted parameters. Is there a faster way…
Tag: python
Django user activation doesnt work with token — TypeError: a bytes-like object is required, not ‘str’
So I have the following token activation setup for users to activate their accounts However, when I click the emailed link, the view always returns the isn’t valid path. Some debugging pointed me to print(User.objects.get(pk=uid)) which returns TypeError: a bytes-like object is required, not ‘str&…
Process columns based on column names in another column
I like to select cells for processing by choosing column names contained in a different column. For clarity, input and output are given below. Column ‘a’ contains the column names for setting the value to None for each row. I tried to code as below but keep getting errors. Input Output Answer Chec…
Returning value in a nested function when using memoization
I am trying to implement a count variable in the function below using dynamic programming specifically memoization. The method calculates the value in a Fibonacci sequence at a given index. I cannot figure out why the count (in this case the number of times this program executes) is not returned. Output: Addi…
Colors in pillow-generated image viewed in tkinter don’t match colors in saved file
I wrote a Python script that fuses a stereo pair of images into an anaglyph image. When I view the image in a tkinter application I wrote the image looks good but when I save as a JPG and PNG to Photoshop it looks “confused”. For a while I was wondering if I was crazy but I had my family
How to calculate the outliers in a Pandas dataframe while excluding NaN values
I have a pandas dataframe that should look like this. Some values in this dataframe are outliers. I came across this method of calculating the outliers in every colum using the z score: My goal is to create a column Is Outlier and put a True/False on each row that has/doesn’t have at least one outlier a…
How to print fp in HTTPError?
After seeing this error with my urlopen() function: I wrote a catch exception, but fp is empty when I printed it out. Any ideas? Output: fp isn’t empty in the HTTPError class Output: Thanks. Answer Perhaps I’m dense; but a few items that might help you. You have an errant ” in your print(…
After splitting settings.py file, mod_wsgi failed to exec Python script file. And application = get_wsgi_application() errors occured over and over
Hi everybody I tried to deploy my django project with apache, mod_wsgi in windows. I splited my settings.py like this: source root folder project folder apps config settings init.py base.py local.py prod.py init.py asgi.py urls.py wsgi.py myenv After I splited settings.py, Mod_wsgi failed to exec python scrip…
Replace values in a column with similar values in another column with different size – Python
I have a dataframe with different values in a column (about 6,000 rows), which I need to replace with similar (but differents) values found in another dataframe, which has fewer rows. Store Values to replace Store A 05/15/21 Store A The Store B 04/01/21 Store B Store letter B 11/12/21 Store C Store C 10/2…
Python BeautifulSoup4 news scraper giving odd error
I am trying to make a news scraper with BS4 and I am able to get the html code from the website (cnn) and this is my code: but its giving me this error I have no idea what is causing this, Thanks! Answer If the string topic is not found on the page, then prices will be an empty