Is there a way of changing structure of nested dictionary? I have a column in dataframe with many rows of dictionaries, which looks like that: Is there a way of modifying structure, so that it will looks like without changing actual values? Answer You should read about the function apply() in pandas. You buil…
Tag: python
How to organise multiple stock data in pandas dataframe for plotting
I have over a hundred stocks (actually crypto but that does not matter) I wish to plot, all on the same line plot. I end up with a dataframe that looks like this: I don’t know how to make a line plot from this dataframe, I don’t even know if it is possible. Is there a way? Or is there
‘can’t find ‘__ main __’ module’ in command prompt
So I was following the tutorial on some basic set-up (cloning the folder onto my own pc) of a project If you have chosen to install python (and already set up PATH variable for python.exe) then follow the instructions: Open the command prompt and change the directory to the project folder as mentioned above b…
discord.py’s on_member_leave event isn’t working
Making a bot that logs basic events, like on_member_join and on_message has been working, but when I implemented the on_member_leave, that event hasn’t been working. I have previously turned on intents. I’ve tried adding, It still hasn’t been working, what am I doing wrong, what are some thi…
write a program that reads positive numbers from the user and stops if the user entered negative numbers
I am quite new to Python so I am having trouble doing my assignment. I need to create a program that adds an unspecified amount of positive numbers entered by the user, and the program will stop if the user entered a zero or a negative number. Then it prints out the total. I think the problem with my code
I want to select data from different df, how can I speed it up?
I want to take the last data before the specified time from different time intervals df, my code is as follows: On my computer, the running time of get_result_df() is 204ms, how can I speed up the running speed of get_result_df()? I optimized it, and the running time was reduced to 53ms. Is there any room for…
How to mock out AWS resources when testing flask app
I have a Flask app that uses AWS services such as dynamodb. I want to mock these out during unit tests but I’m having trouble doing so. Here is a minimal example that doesn’t work for me: I’m getting an error that the resource does not exist. This means that an AWS call is in fact being made…
How to input embeddings directly to a huggingface model instead of tokens?
I’m going over the huggingface tutorial where they showed how tokens can be fed into a model to generate hidden representations: But how can I input word embeddings directly instead of tokens? That is, I have another model that generates word embeddings and I need to feed those into the model Answer Mos…
How can I remove in Python “-” from spaces and keep them between words?
I have a string with different words in Python. The string is connected with a “-” between the words and the spaces, as shown in the example below. I tried using the replace and split method to remove the “-” in the spaces. However, I can only get it to remove them all, but I need the …
Scaler fitted in a pipeline turns out to be not fitted yet
Please consider this code: I get this message: Why is the scaler not fitted? Answer When passing a pipeline or an estimator to RFE, it essentially gets cloned by the RFE and fit until it finds the best fit with the reduced number of features. To access this fit estimator you can use fit_pipeline = rfe.estimat…