October 22, 2024
Chicago 12, Melborne City, USA
python

Using for loop reading with multiprocessing missing iterables

Sorry if I’m wording this wrong, below is my script, I’m trying to figure out why when I review the archive file (that I created) I only see 9874 lines when the file to open/read has 10000. I guess I’m trying to uderstand why some iterations are missing. I’ve tried it a few times and

Read More
python

Pandas: Merge by common column retaining all other columns and sort by common column

I have two dataframes, with one column that has unique values in each dataframe but is the same in both dataframe (some of the values match), I want to merge the two dataframes matching the values on the columns (x must match y column) df1 = pd.DataFrame({'x': ['1', '2', '3', '4', '5', '6'], 'y': ['A',

Read More
python

Dealing with interlacing lock in Python3

I am trying to implement the following logic in Python3: def f(): lock1.acquire() task_protected_by_lock1() # Might acquire lock2 internally lock2.acquire() task_protected_by_lock1_and_lock2() lock1.release() task_protected_by_lock2() # Might acquire lock1 internally lock2.release() However, I found it impossible to correctly handle SIGINT because it will raise a KeyBoardInterrupt exception at random location. I need to guarantee that lock1 and

Read More
python

Python Protocol using keyword-only arguments requires implementation to have different signature

I’m on python 3.10. Here is the protocol I defined: class OnSubscribeFunc(Protocol): def __call__(self, instrument: str, *, send: Callable[[str], Coroutine]) -> AsyncGenerator: ... When create a method that implements it like this: async def subscribe(self, instrument: str, *, send: Callable[[str], Coroutine]): yield ... I get this warning: Expected type 'OnSubscribeFunc', got '(instrument: str, Any, send:

Read More
python

rdflib converting a complex CSV to a Graph – chained objects

I’m fairly new to OWL and RDFlib, so my apologies if any of my terminology is off. I have a CSV that I’d like to convert into a knowledge graph, where each row becomes a sort of top level subject, and then has properties linked to it. While not important for the problem, the knowledge

Read More
python

How to display axis tick labels with a detailed scientific notation offset?

I am trying to produce a figure with multiple subplots where the axis tick labels of each subplot should be formatting in the same way. As the numbers are large, displaying tick labels in a legible format is tricky. I like the matplotlib format of a detailed scientific offset b x 10^c (see plot below

Read More
python

Floating Window with Python

I am coding an app in kivy python to put on my phone in which – after a certain amount of time – I want a window to ‘pop-up’ (float) over whatever app I’m currently using. I then want to be able to type an input into the window and it disappears. My problem is

Read More
python

I want to solve this question in Python, but I couldn't include all the solutions. I tried hard, but I don't know what the problem is

You are given a string of encrypted text (ciphertext). The encryption algorithm used to create the ciphertext simply shifts all the alphabetic characters in the original (unencrypted) string by the same amount. But you don”t know what this amount is. Write the decipher function that takes the encrypted string as input, and returns the original,

Read More
python

Module not found after creating from .conda file

I am working with an offline device, so I am trying to install packages via .conda files or .tar.bz2 files. In particular, I am trying to install python-levenshtein. I ran the following commands: (myenv) C:\Users\my_user>conda install --offline "C:\Users\my_user\.conda\pkgs\python-levenshtein-0.26.0-pyhd8ed1ab_0.conda I placed the conda file within the packages directory in conda. Additionally, the package is also visible

Read More
python

exported jupyter notebook has different syntax highlighting

When I have this Python code in a Jupyter notebook: df = pd.read_csv("data.csv", index_col=0) print(df.shape) The read_csv and shape are blue, the "data.csv" is red, and the 0 and print are green. When I export the notebook to HTML, the read_csv, shape, and print no longer have syntax highlighting. Also, in my jupyter notebook: for

Read More