Is there a way to set the .toml file up so you will have the dependencies installed in a certain order with Poetry? Imagine I have the following .toml: How can I make sure wxPython always is installed first? Answer There is no way to tell Poetry to install packages in a certain order. The reason for this is, …
Tag: python
regex whole string match between numbers
I want to extract a whole word from a sentence. Thanks to this answer, I can get whole words in cases like: where symbols next to the word don’t bother. However if there’s a number it doesn’t find the word. How should I modify the expression to match cases where there’s a number next t…
replace whitespace with comma in multiline string (doc string), but keeping end-of-line
I have a multiline string (and not a text file) like this: The column white spaces are unequal. I want to replace the whitespace with a comma, but keep the end-of-line. So the result would look like this: …or alternatively as a pandas dataframe. what i have tried I can use replace(”) with differen…
How to check if a row of a Pandas dataframe has a cell with a specific value and if it does modify the last cell?
I have a dataframe df: name age_5_9 age_10_14 age_15_19 Alice no bones broken no bones broken broke 1 bone Bob no bones broken broke 2 bones no bones broken Charles no bones broken no bones broken no bones broken I would like to create a column broke_a_bone that is 1 when any of the rows has a value ‘br…
How to append items in dictionary nested list?
I have a file with two columns of data, for example: I want to obtain a dictionary with first column as the key and the second column as values, something like the following: Answer You haven’t specified full details of the content of your file. I am assuming you don’t have any column names. With …
GlobalHotKeys pynput not working not reacting to function keys
community. I’m trying to put together a quick hotkey script in python here. For some reason it doesn’t react to function keys, meaning the expression ‘<ctrl>+<F2>’: function_1 doesn’t work. I was not able to find any clues in the official documentation or other exampl…
How to improve performance of dataframe slices matching?
I need to improve the performance of the following dataframe slices matching. What I need to do is find the matching trips between 2 dataframes, according to the sequence column values with order conserved. My 2 dataframes: Expected output: This is the following code I’ m using: Despite working, this is…
Looping through HTML & following links
I am writing a code that is supposed to open a url, identify the 3rd link and repeat this process 3 times (each time with the new url). I wrote a loop (below), but it seems to each time sart over with the original url. Can someone help me fix my code? Answer You need to define the empty list
Python – Check if value is unique in dictionary of lists
Is there a way to check if a value is unique for a specific list, within a dictionary of lists? If yes, I would like to know in which key/list pair/s the value is present. For example: {1: [3, 4, 5], 2: [4], 3: [5], 6: [3, 5, 9], 8: [3 ,8]} I want to check if 3 is present
Panel data: take first observation of each group, repeat row and adjust certain values
I have a large Pandas dataframe that looks as follows (85k rows): My goal is the following: For the first observation of each ID for which the BEGDT > Inception, copy the row and change the BEGDT to Inception and the ENDDT to BEGDT – 1 day of the initially copied row. Accordingly, the final output sh…