I have a dataframe. I would like to perform a transformation that combines a set of columns and stuff into a json string. The columns to be combined is known ahead of time. The output should look like something below. Is there any sugggested method to achieve this? Appreciate any help on this. Answer You can …
Tag: python
replace multiple whitespace with single space but keep new lines in regex match (python)
How can I clean up the following text with regex in python? I’m trying to replace multiple whitespaces and tabs with single spaces, but preserve new lines. test = “This is a test. n Blah blah.” In my new string, I want it to be: “This is a test. n Blah blah.” I’ve tried the…
Python 3: How do I add input and a string to the same line?
I have to put the input on the same line as the string and can’t figure out how. Here’s the code: Answer The function input() takes in a string to print so you can do this: And it will print the string before taking input without adding a newline
Add pivot table in excel with python
I am trying to add a pivot table in excel using python script with pandas but not able to do so. I won’t to count number of missed and met entries for each priority. Excel script: Excel data: Priority SLA p1 Met p2 Missed p3 Missed p2 Missed p3 Missed desired output: Priority Met Missed p1 1 0 p2 1
Running FastAPI multiple process error after pyinstaller
I am running python FastAPI with UVICORN with multiple processors (5 processes),It is running smoothly from the code, but when I tried make the exe from pyinstaller and try to run the file, it is showing error. filename: main.py Output code from source I make a single file using pyinstaller with the following…
The method doesn’t want to enter in for loo
What’s the problem with this damn loop? I don’t understand why the method doesn’t acces the loop. I tried to make videos a list because cursor type can’t be parsed. If I’m running this for loop alone, without the if statement above, it works. Answer videos is an iterable, and you…
how to ignore null values in DataFrame when comparing columns
I am new to Pandas and learning. I am reading excel to DataFrame and comparing columns and highlight the column that’s not same. For example if Column A is not same as Column B then highlight the Column B. However I have some null values in Column A and Column B. When I execute the code, I don’t w…
Why is this array changing when I’m not operating on it?
I have two arrays: And I’m running the foll)owing code: I get the following result: Why are the last elements changed? I don’t see why X is changed by indexing some elements. edit: added np.array Answer Output:
Why can’t I write to a text file? Python 3.10
I tried ‘r+’ and ‘w+’ but couldn’t write. I’m not getting any errors. what could be wrong? I had changed the position WITH but nothing changed. I want to write the STRING of the ARTICLE TITLE in a text file. I can write to csv. The error I am seeing now is this. UnicodeEnco…
Error using docker compose in AWS Code Pipeline
I’m deploying my dockerized Django app using AWS Code Pipeline but facing some errors of Docker. error: docker-compose-deploy.yml buildspec.yml Answer Docker Hub limits the number of Docker image downloads (“pulls”) based on the account type of the user pulling the image. Pull rates limits are based on …