python

How to change columns values(list) using another data frame in Python

How to change columns values(list) using another data frame in Python Question: I have two data frame, I need to change column values of first data frame that are in list, using second data frame. First Data frame df1 = pd.DataFrame({‘title’:[‘The Godfather’,’Fight Club’,’The Empire’], genre_ids’:[[18, 80],[18],[12, 28, 878]]}) title genre_ids 0 The Godfather [18, 80] …

Total answers: 2

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue?

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue? Question: I have the following code for a server listening on a port: def handle_oracle_query(self, sock, address): sockIn = sock.makefile(‘rb’) sockOut = sock.makefile(‘wb’) line = sockIn.readline() …

Total answers: 2

RandomForest project

RandomForest project Question: I am very new and fresh to machine learning and this is my first project I am working on as part of a college course. I chose UK football (soccer) matches. I have chosen to use a Random Forest. Using different sources I have managed to get 20 years worth of data …

Total answers: 2

Ambiguous output with python and files

Ambiguous output with python and files Question: I was testing how filestreams work in python and I wrote some code as follows: with open(‘test2.txt’) as f: while r := f.read(1): print(repr(r), f.tell(), sep=’tindex:’, end=’n***************n’) Contents of test2.txt are as follows: 012345 6789 I ran the code and the output is as follows: ‘0’ index:1 *************** …

Total answers: 1

How to disable application/json in Swagger UI autodocs of a FastAPI application?

How to disable application/json in Swagger UI autodocs of a FastAPI application? Question: My API can return only a file: @router.get( "/partners/{partner_id}/rsr-requests/{rsr_request_id}/{document_path}", responses={200: {"content": {"application/octet-stream": {}}, "description": "Файл"}} ) async def download_rsr_document(…): pass But in Swagger UI, I can see that application/json still remains. How to disable it? Asked By: Альберт Александров || Source Answers: …

Total answers: 2

PermissionError: [Errno 13] Permission denied in a python program

PermissionError: [Errno 13] Permission denied in a python program Question: when I run my python program I encounter an error saying:PermissionError: [Errno 13] Permission denied and I do not know why it is not working I was wondering if i could somehow elevate myself when running this program. I am using vscode and I am …

Total answers: 1

How do I choose individual colors for contours in matplotlib

How do I choose individual colors for contours in matplotlib Question: In my short python code below I am plotting risk levels based on values in a csv file and using a shapefile. The code works, but I would like to select specific individual colors for each level, namely green, yellow, orange and red. Currently …

Total answers: 1

How to solve a system of linear equations in Python with an iterative method?

How to solve a system of linear equations in Python with an iterative method? Question: I have a system of linear equations represented as strings in Python, and I need to find integer values (positive or negative) for each of the variables that satisfy all equations simultaneously without contradictions. The number of variables and equations …

Total answers: 1