The table looks like the following: text dummy1 days op123ac 1 2000-01-01 op123ac 0 2000-01-04 op123ac 0 2000-01-07 op123ac 0 2000-01-10 op1248ab 0 2000-01-17 op1248ab 1 2000-01-20 op1248ab 1 2000-01-23 op1248ab 1 2000-01-26 Each unique “text” have four repeated values correspond to four unique &#…
Tag: python
I need help understanding the problem here
I’m trying to make an age calculator that is accurate enough to calculate age based on whether the person has had their birth day this year or not. The problem is something is wrong with my code so even thought when I input “No” it should deduct -1 from the age result but it doesn’t do…
Capture python output to variable
I’m trying to automate pybaseball from player lookup to data extraction and can’t seem to get past the first step of setting the player id as a variable. I’m utilizing the following code to pull player id: The output from the above lines are (exact copy/paste): Is there a method for setting …
How to search videos on youtube and get link with python
i’m trying to search songs based on song titles and artists names from youtube and trying to get the link of the 1st video that appeared in the search queue and download the video, but i’m facing this error. Can u help me to fix this error ? This is how I tried to implement….. [here, ‘…
Why does calling the __exit__ method on unittest.mock._patch throw an IndexError?
When I define a function and patch it using the with statement it runs fine. Output: My understanding is that using the with statement would cause the __enter__ and __exit__ methods to be called on the patch object. So I thought that would be equivalent to doing this: The output from the some_func call is the…
Python deque maxlen does not show
I have result but in book Fluent Python (2019), I see maxlen, like this Is the different cause by version different? Answer This seems to be caused by IPython. If you do print(dq) or print(repr(dq)), you get your expected output, and same in a normal REPL. Update: I’ve submitted a PR to IPython to fix t…
Add missing rows in pandas DataFrame
I have a DataFrame that looks like this: What I want to get is: In short, for each id, add the time rows missing with value 0. How do I do this? I wrote something with a loop, but it’s going to be prohibitively slow for my use case which has several million rows Answer Here’s one way using groupby…
How to remove brackets from multi-value keys when converting to dataframes or extend values of a key without extraneous characters
The above code handles a nested dictionary to dataframe conversion perfectly fine but if you have a nested dictionary created with the .append() or .extend() method it adds extraneous brackets[] and quotes ” which is making downstream analysis difficult. For example for a nested dictionary like this: cr…
Tkinter – How to create a custom Tkinter Frame object? I tried but it doesn’t work
I tried to create some custom tkinter objects to build my GUIs easier but unfortunately I couldn’t. For example, what about if I want an object that identify a frame placed inside another one? To do that I wrote it: Main code (file name: test.py): Library (file name: ttk_plus.py): If I run test.py, the …
Replacing day in date with last day of month
I’ve got a dataframe with column ‘date’, containing yyyy-mm-dd 00:00:00. Python automatically assigned first day of every quarterly month, but I want last day of same month. I’ve tried: and without any success. sample of df: date value 1990-07-01 00:00:00 46.7 1990-10-01 00:00:00 54.2 …