I have some stock market data in excel covering the past 20 years or so which contains gaps from holidays and weekends. I wish to interpolate over those missing dates to obtain the approximate stock index for those days. I’ve read both columns into Python using pandas and assigned them to their respecti…
how to remove empty space from bars for a specific group, that was plotted as seaborn bar plot on data in pandas dataframe
I have a dataset which looks like this: When I am plotting this data using the following code: I get the following issue (there is always some space between the bars of IND): Whatever I had tried, it is not going away. How to fix the issue? Answer This happens because you’ve got missing values in your D…
Plotly: using fig.update_xaxes showes wrong month
I am looking for a solution to show the x_axis correct. the date 2021-01-31 is displayed as “Feb 2021”. i would like to show it as “Jan 2021”. thanks for help! Answer You can force the ticks to start at 2021-01-31 by setting the starting tick to the starting date of your data sdate. I …
Python – getting lost around async
As the title said – I’m having a problem with async stuff. What I’m trying to achieve is written under every function. Sadly in this state of code I’m getting and error: TypeError: object StreamReader can’t be used in ‘await’ expression and at the end RuntimeError: Ev…
Can this for loop be vectorized?
Can this for loop be vectorized maybe by expanding dimensions and then collapsing it? I got the hint from somewhere that I can replace with Answer It can be vectorized by expanding dimensions as you suggested. I think the secret sauce is using np.tril to zero out terms in the progression before summing:
Replacing the body of a specific function in python code
Assume that I have a python source file, the names of a specific class and a from this file, and a string to replace the body of that function. How can I write a program to do this automatically? I am not looking for “string”-matching solutions. I am mostly looking for a python library that might …
Python/pip process are killed in virtualenv (Apple M1 chip)
When I execute pip or python in MacBook M1 chip virtualenv, the process always terminates immediately with message like: or Python and pip in M1 MacBook native environment run fine. Only in the virtualenv they don’t work. Answer After some research, I find out it is related with “x86_64” and…
Different runtime behavior for non-generic typing
Consider these two scenarios: and Running the former (expectedly) throws a TypeError: However the latter doesn’t, and proceeds to the print statement without issue: I would expect a TypeError in both cases. Why is there no TypeError when the Queue[int] type is inside of a class’s __init__ method? …
Make Discord BOT get random image from a ftp server (Filezilla)
I’m just gonna say it right away that I have no experience whatsoever in python. I’m trying to make a bot for a private Discord server that posts a random image (.jpg) from a ftp server (root directory) after typing ‘$gimme’. #file names are random jibberish I’ve searched for hou…
IllegalMonthError in Python datefinder
I am trying to extract dates from email texts using datefinder python library. Below is a the code snippet of what I am trying to do. datefinder tries to construct all the numbers in the email to dates. I get lot of false positives. I can remove those using some logic. But i get IllegalMonthError in some emai…