Have a Jupyter Lab notebook which at a certain point compares two dataframes. df_lastweek is an extraction of only last week’s data while the df_lastmonth is the extraction of the last 30 days. The two dataframes are different the latter having more rows than the former. The following if comparing the two different dataframes does not trigger: while the next
Tag: python
Remove duplicate value on nested list python
I have a problem here when I want to remove duplicate in a list that has a nested list, how can I remove the duplicate value from list? What I got here from my script, it can remove a duplicate, but the nested list has a different result from what I expect. This is my script: Result: Expected Result: Answer
Right way to do parallel work in python with files and db?
I have very large number of file names (from my PC) inserted in db with status New by default. I want for every file name do some operations (change file). During change file change file status to Proccesing. After operations change status on Processed. I deside to do it with multiprocessing python module. Right now i have this solution but
Find the average length of all words in a sentence
Given a string consisting of words separated by spaces (one or more). Find the average length of all words. Average word length = total number of characters in words (excluding spaces) divided by the number of words. My attempt: But input is incorrect, can you help me? Answer When you’re stuck, one nice trick is to use very verbose variable
Not able to do Insert operation in CRUD
I am making a CRUD of colors with color_name and color_description. While trying to insert the details the error below has be shown: below is the insert and show function that I have tried out model HTML of insert_color HTML of show color I have checked the names assigned and they are matching, so where am I going wrong? Answer
Django csv upload to db works but throws error
I have created an app named customer within a project named Website using django. I have created a csv upload in the admin area which is connected to the Postgres db. However the CSV file is still added to the db but the error screen is displayed. Even more strangely if I a notepad doc as csv containing the data
Continue in if conditional python loop is not working
Results are I was expecting that it would identify the first pattern DS in the first string in list a, then move to next element. However, it proceed to identify DY as well. What am I doing incorrectly? Any help is appreciated. Thanks Answer Try to replace continue with break like this Output: Ńontinue actually means that you go to
Spotipy recommendations returns a dictionary with multiple artists instead of a single track
I’m trying to get a single recommended track when passing in a genre to the recommendations() function in the Spotipy library. This is my code: recommendations = sp.recommendations(seed_genres=[‘pop’], limit=1) I get back a dictionary that seemingly has multiple artists, if anyone has tips on how to extract data from a dictionary like this, please let me know as I am
How add value in second row into first row?
I would like to add a new columns from a values of ‘Pr’ in second rows for each value same id and date. Input a: ID Date order Date restock Pr Infos 778005 2022-04-07 11:34:46.0 NaN 87.0;113001.0;00 a 778005 2022-04-07 11:34:46.0 NaN 87.0;113159.0;FC at 7001 2021-12-10 13:50:46.0 2021-12-13 00:00:00.0 87.0;271007.0;BV b 7001 2021-12-10 13:50:46.0 2021-12-13 00:00:00.0 87.0;286005.0;BV bt 778005 2022-05-24
Slice multidimensional numpy array from max in a given axis
I have a 3-dimensional array a of shape (n, m, l). I extract one column j from it’s last axis and compute the maximum index along the first axis like follows: Now I’d like to slice the original array a to get all the information based on the index where the column j is maximal. I.e. I’d like an numpythonic