I’m a newbie, so please excuse me if I use incorrect terms. I have a df with customer purchasing info and customers are identified by a unique user_id. Each item a user_id buys in each transaction creates a new row (if a customer buys 5 products in 1 transaction, 5 different rows are created with that p…
Tag: pandas
Pandas: Get year to date dates from previous year
I want to compare the dates ranging from January 1st till the current day, from this year versus from last year. example: get the rows with dates ranging from january 1st till november 29th 2020 get the rows with dates ranging from january 1st till november 29th 2021 here is what I have tryed doing, and the o…
Python pandas extract data from nested list
For a personal project, I’m calling data from the Google Books API and uploading the fields I want to mySQL. I’ve successfully made the API request and received data. The data received is nested and i want to place this in a dataframe. Now my code works with the “first” column (no inde…
Degeneracy given a graph
An exercise requires to determine the degenerative level of a graph. To do that, I have found useful the following code (source: https://www.geeksforgeeks.org/find-k-cores-graph/) which represents an undirected graph using adjacency list representation An example of data that I am using for building a graph i…
How to transform a .csv string list representation to list?
Suppose a .csv file which looks like this: title: is the name of the column and [senior innovation manager] is the first row. Note: both strings (title and row) look exactly as written here. The idea is to convert this list string representation to an actual python list: However when tried the above code the …
Merge Pandas Dataframes based on substring or partial match in another Dataframe
I have two sample data frames: Using this will result result in an empty dataframe. How could I go about using a merge to use a substring / partial match from df2[‘Group_Var’] in df1[‘Model’]? Perhaps using the str.contains() method as part of the merge? Just for context my expected ou…
Find max by year and return date on which max occurred in Pandas with dates as index
I have this dataframe I would like to compute the max for each year and the date where it happens. I am struggling because I would like to keep indeed the date as index. Indeed I read it as: I know that I could resample as but in this case I would lose the information about the location of the
Scrape Historical Bitcoin Data from Coinmarketcap with BeautifulSoup
I’m trying to scrape Historical Bitcoin Data from coinmarketcap.com in order to get close, volume, date, high and low values since the beginning of the year until Sep 30, 2021. After going through threads and videos for hours, and I’m new to scraping with Python, I don’t know what my mistake…
Make list after groupby in pandas using apply() function
I have this dataframe: My goal is to keep tracking the values in column2, based on the letters of column1 separated by(:), the output should look like this: What’s the most pythonic way to do this: At the moment I’m able to group by the column 1 and I’m trying to use the apply() function, bu…
Appending value from a row onto the same row but in a new column when condition in for loop is met
I need to attach the numeric values, whichever is less, from columns, R2ESL or MCL, into a new column, Lesser Value, for each row (ex. A, B, C). For example, for param A, MCL with value of 7 is less than R2ESL with value of 10. I want to get 7 into a new column (Lesser Value), but on the