I have a simple script transforming data in a dataframe: The above seems to work fine. I have tried rewriting the last two lines to: However, this fails and gives a value error: I am trying to understand why it can’t be used in the above way. My pad_value function seems clunky – I wonder if there …
Tag: python
Is there any Python code to help me replace the years of every date by 2022
I have a pandas dataframe column named disbursal_date which is a datetime: and so on… I want to keep the date and month part and replace the years by 2022 for all values. I tried using df[‘disbursal_date’].map(lambda x: x.replace(year=2022)) but this didn’t work for me. Answer You need…
How to drop rows from a pandas dataframe based on a pre-made list
I have a big dataset. It’s about news reading. I’m trying to clean it. I created a checklist of cities that I want to keep (the set has all the cities). How can I drop the rows based on that checklist? For example, I have a checklist (as a list) that contains all the french cities. How can I drop
How to understand the error in my Python program
I’m trying to code a program that prints the factors of a number, just as shown in the attached image, but the outcome is totally not what I’m expecting. (I just want the code to return factors of the specified number.) What am I doing wrong and what is the correct way of doing it? Code: Output: A…
Cumulative of last 12 months from latest communication date?
I’m looking at counting the number of interactions grouped by ID in the last 12 months for each unique ID. The count starts from the latest date to the last one grouped by ID. Output is something like the below. How can I achieve this in Pandas? Any function that would count the months based on the date…
How run an mp4 in Tkinter?
I have been trying to run an mp4 in Tkinter and have been getting an error message about a couple line errors in –main–.py, and runpy.py. I’m a newbie and this is confusing me because I’ve been spending hours trying to fix this. I am also having a problem in the file path for my video,…
Change bubble size in altair without changing font size
I am trying to create a altair bubble chart. The sample code and sample dataframe is below: I want the size of the bubble based on Market_cap and put names of companies alongside. The problem is font size of names is also changing as per the bubble size. How can this I create this bubble chart with different …
Draw longest possible vertical line between two curves in seaborn
I currently have a plot like this (consider that data is the dataframe I pasted at the very bottom): Which produces: Now, I want to know how can I annotate a line in this plot, such that it is located between the curves, at the x-Axis value where the distance between curves are maximized. I would also need to…
Scraping all entries of lazyloading page using python
See this page with ECB press releases. These go back to 1997, so it would be nice to automate getting all the links going back in time. I found the tag that harbours the links (‘//*[@id=”lazyload-container”]’), but it only gets the most recent links. How to get the rest? Answer The dat…
How to draw the precision-recall curve for a segmentation model?
I am using an U-Net for segmenting my data of interest. The masks are grayscale and of size (256,256,1). There are 80 images in the test set. The test images (X_ts) and their respective ground-truth masks (Y_ts) are constructed, saved, and loaded like this: The shape of Y_ts (ground truth) is therefore (80,25…