How can I convert np.nan into the new pd.NA format, given the pd.DataFrame comprises float? Making use of pd.convert_dtypes() doesn’t seem to work when df comprises float. This conversion is however working fine when df contains int. Answer From v1.2 this now works with floats by default and if you want…
Tag: python
how to get only specific values from dictionary using key in python
I have this kind of 50 dictionary means that I have over 50 kind of dictionary for different values. like symbol and other key value. I want to get only symbol and open values in a list. What I have tried: Here data is the dictionary as mentioned above. please help. here is an example of several dictionaries.…
How to convert the string to a list of dictionary objects containing two keys with respective values?
I have an external file, and I have to convert the strings from the external file to a list of dictionary objects, containing keys and with respective values. The problem is I keep getting error on the code I already tried, such as “too many values to unpack”. I am really stuck in here. Here is th…
How to test a Faust agent that sends data to a sink?
I am trying to write unit tests using pytest for my Faust application. I have referred to the documentation here but it does not mention what to do when my Faust agent is sending data to a sink. Without a sink, my tests are working fine but when I use a sink, I get this error: I have tried various
sending order to open a position via MetaTrader5 python module and nothing happens
I followed Metatrader5 python documentation and this answer in stack overflow I try to open a sell position: Nothing happens and there is no reaction in applications terminal. I also check Trade and History section in Metatrader5 to find some related information but I find out nothing. how can I monitor the l…
Change contrast and sharpness of a Picture in Python
I’m new to coding, some my code isn’t the cleanest (as evidenced below). Is there a more efficent way to change both the sharpness and contrast with Pillow in python without having to save and open the file twice? My horrible code: Answer You can do it without saving to disk like this: Transforms …
How to add watermark in all pages of PDF files with python?
I’m try to adding watermark to every pages of my PDF file.My PDF files have 58 pages but my output file has get only last page in my PDF file. This’s my code: Please tell me how to add watermark all pages. Answer You’re rewriting your “merged” file for each page. Try something li…
the graphs of the two projectiles does not work properly when complementary angles(eg 30 and 60) are passes to xy_plot1 and xyplot2 function
Answer Be careful! Your theta argument for the xyplot() function is in degrees, but inside your function, the math.sin() function takes the argument for the angle in units of radians. The easiest fix is to provide your theta argument in units of radians instead of degrees. You also don’t need both funct…
OSError: [WinError 740] The requested operation requires elevation
I am having a simple code which has an image called “try.png” and I want to convert it from Image to Text using pytesseract but I am having some issues with the code. But it’s giving me an error. Any idea on how to over come this error Answer tesseract-ocr-setup-4.00.00dev.exe sounds like a …
Multiple Columns for HUE parameter in Seaborn violinplot
I am working with tips data set, and here is the head of data set. My code is I want a violinplot of day with total_bill in which hue is sex and smoker, but I can not find any option to set multiple values of hue. Is there any way? Answer You could use a seaborn.catplot in order to use