I have a simple function which counts the files in a directory. I want to test this the following way. This works, but is of course very repetetive: Is there an easier way to write this? Desired: Answer Try just a simple for loop like
Tag: python
I need to keep multiplying found values by two with a list and a value
They gave me the first two lines of code. I thought I knew how to do it but I don’t really understand what I’m missing. Answer I think this is what you’re trying to accomplish?
Iterate through multiple combo boxes in a container pyqt
I’m having a problem with extracting data from multiple comboboxes at once. I have around 10 comboboxes in a container. I could extract the data individual but that would result in repeated code. This is what I have so far but doesn’t seem to work at all: Answer First of all you will need to have all the comb…
How to Update a field in Django
I want to Update only name field if only name is sent from frontend, update only image if only image is sent from frontend, update both if name & image is sent from frontend In Django Answer You can construct a dictionary that only contains the key-value pairs to update and then use .update(…) [Django-doc…
Output missing dates by group of columns
I have time series of y per store and product stored in the following dataframe: I would like to output all the missing dates per store, product and return the following result: Answer Use groupby_resample: Details: Update: If you have a date in the ds column without a value in the y column, just use fillna({…
Python: converting list of strings into a string which illustrates the list
I’m searching a simple method for converting a list of strings (e.g. [‘test 1’, ‘test 2’ , ‘test 3’] ) into a string whereby the list of objects doesn’t have some quotation mark. That means in our example (‘[test 1, test 2, test 3]’). My first approa…
How to detect closed websocket in asyncio.gather(*tasks)
I have a list of asyncio tasks which contains with connecting,handshaking and receiving data from a websocket. This process is running correctly but sometimes the connection of one of the websocket (or maybe all of them) is closed. How can I detect and make a new conncetion to the closed one? Here is the code…
Can repeating query be saved?
In my Python / Sqlite program, I am running queries like this So the “basic” query is the same, and the rows Sqlite gathers are the same, but because of the different grouping , I have to run the same query multiple times. I wonder if there is a way to achieve the same output more effectively, ie.…
How to order categorical month variable when plotting using matplotlib?
I am doing some topic modelling, and I am interested in showing how the average topic weight changes over time. The problem arises when I plot it using matplotlib (version 3.3.4). On the x-axis I would like to have the categorical month_year variable. The problem is that it is not ordered in a sensible way. I…
How do you slice a cross section in pandas or numpy?
I have the following data frame which can be copy/pasted and made to a data frame with: df = pd.read_clipboard() I would like to take a cross section from it, I want something like say: [1, 4, 9, 1, 10, 6, 4, 0, 4, 6, 10, 1, 9, 4, 1]) which is index df.loc[1, 0], df.loc[2, 1], df.loc[3, 2], df.loc[4,