I have a list of dictionaries that have an “index” and a “weight” value. I want to average the dictionaries based on any unique index. So, with the below example, how can I find the average weight for any given index (e.g. 0, 1, 250, etc.)? There will be 8 total elements for each index…
Tag: python
missing some messages in websocket client?
I am trying to implement a websocket client that connects to the popular crypto exchange FTX. I have simplified my problem to the following example code below: The output of the program overall is as expected, but with one major problem: the cumulative trading volume that gets output to the console is WAY too…
Add new columns to dataframe from dictionary for every row
I want to add columns in a dataframe from a dictionary where keys are randomly generated and for every row of the dataframe the values of keys should be added and the dataframe is like following: How can I do it ? expecetd outcome: Answer You can craft a DataFrame from the dictionary and use a cross merge: ou…
count sequence of value in df
I have df: I want to count the condition that the value in val column is <=3 at least 3 times in the same id and color in a row(in sequence), and when the condition is true, to return the id and color. for example I will get here 1,y thanks Answer You can use: output: [(1, ‘y’)] intermediate s:
How can I create a loop with my conditions
i am looking for help. We need to write a program that prints all numbers in the range of (n -20,n + 20). In addition, the program asks you beforehand to input a number. If that number is not even or multiple of 10, you need to take a guess again. Only if the number is even and multiple by
Lineplot – plot a single legend for uneven number of subplots
I’m working on the following graph where I’d like to plot is single legend that applies to all, essentially this would be a small box where blue color line is AB=0 and green line is AB = 1. Moreover, I’m using plt.subplot(… since it is possible that might have to deal with uneven numbe…
Docker-Compose Output File To Local Host
I have the below docker-compose.yaml file that sets up a database and runs a python script To run it I perform the following Here is the Dockerfile Now this works fine I can see the data has been properly populated under the generated in the msql database. The python file at the end of the script should dump …
Retrieve all occurrencies from selected attributes to separate column in pandas
want to extract color from the product descriptions. I tried to use NER but it was nt successful. Now I am trying to define a list and match it with description. I have data in dataframe column like this: I defined also the list of colors What I did was to create a matcher And I applied it to the
Difference of Double Quotes and Vertical bar in yaml
I’m writing a Python script that creates a YAML file according to DataFrame and I came across this: vs Are they technically the same or am I missing something? If they are not the same, how do I make the second version like the first that uses a vertical bar. Answer They are technically not the same, bu…
Safety and Clobber errors during clone of anaconda base environment (Version 2022.05)
I installed the anaconda distribution (version 2022.05) on a windows 10 (64 bit) machine. During installation I followed the recommendations given here (installed it only for myself and didn’t add anaconda to the PATH variable). I didn’t change any setting, so you can assume a virgin anaconda with…