pandas-explode

Explode column of objects python pandas dataframe

Explode column of objects python pandas dataframe Question: I am trying to explode a column to create new rows within pandas data frame. What would be the best approach to this? Input: SKU Quantity Name YY-123-671 5 drawer YY-345-111-WH,YY-345-111-RD,YY-345-111-BL 10 desk LK-896-001 1 lamp Desired Output: SKU Quantity Name YY-123-671 5 drawer YY-345-111-WH 10 desk …

Total answers: 1

Explode multiple columns in CSV with varying/unmatching element counts using Pandas

Explode multiple columns in CSV with varying/unmatching element counts using Pandas Question: I’m trying to use the explode function in pandas on 2 columns in a CSV that have varying element counts. I understand that one of the limitations of a multi-explode currently is that you can’t have nonmatching element counts in the target columns, …

Total answers: 1

Using groupby() on an exploded pandas DataFrame returns a data frame where indeces are repeated but they have different attributes

Using groupby() on an exploded pandas DataFrame returns a data frame where indeces are repeated but they have different attributes Question: I am working with a dataset found in kaggle (https://www.kaggle.com/datasets/shivamb/netflix-shows) which has data regarding different productions on Netflix. I am looking to answer the following question: How many productions are produced from each country. …

Total answers: 2

Call pandas explode on one column, and divide the other columns accordingly

Call pandas explode on one column, and divide the other columns accordingly Question: I have a dataframe like the one below d = {"to_explode": [[1, 2, 3], [4, 5], [6, 7, 8, 9]], "numbers": [3, 2, 4]} df = pd.DataFrame(data=d) to_explode numbers 0 [1, 2, 3] 3 1 [4, 5] 4 2 [6, 7, 8, …

Total answers: 1

ValueError: cannot reindex from a duplicate axis in explode

ValueError: cannot reindex from a duplicate axis in explode Question: I am trying to expand the dataframe from one row to multiple rows based on two columns. Following is the snapshot of the actual data. initial_row_index Date Product_ID No_of_items 1 2021-07-11 [‘A13N’, ‘A4BE’,’5GH$’] [3,5,1] 2 2021-07-12 [‘A13N’, ‘X9HE’,’7H3T’] [7,2,4] 3 2021-07-13 [‘A4BE’, ‘X9HE’] [8,4] I …

Total answers: 2

How to implode(reverse of pandas explode) based on a column

How to implode(reverse of pandas explode) based on a column Question: I have a dataframe df like below NETWORK config_id APPLICABLE_DAYS Case Delivery 0 Grocery 5399 SUN 10 1 1 Grocery 5399 MON 20 2 2 Grocery 5399 TUE 30 3 3 Grocery 5399 WED 40 4 I want to implode( combine Applicable_days from multiple …

Total answers: 2

Pandas Explode on Multiple columns

Pandas Explode on Multiple columns Question: Using Pandas 0.25.3, trying to explode a couple of columns. Data looks like: d1 = {‘user’:[‘user1′,’user2′,’user3′,’user4’], ‘paid’:[‘Y’,’Y’,’N’,’N’] ‘last_active’:[’11 Jul 2019′,’23 Sep 2018′,’08 Dec 2019′,’03 Mar 2018′], ‘col4′:’data’} I sent this to a dataframe df=pd.DataFrame([d1],columns=d1.keys()) that looks like this: user paid last_active col4 [‘user1′,’user2′,’user3′,’user4’] [‘Y’,’Y’,’N’,’N’] [’11 Jul 2019′,’23 Sep 2018′,’08 …

Total answers: 2

Fill in same amount of characters where other column is NaN

Fill in same amount of characters where other column is NaN Question: I have the following dummy dataframe: df = pd.DataFrame({‘Col1’:[‘a,b,c,d’, ‘e,f,g,h’, ‘i,j,k,l,m’], ‘Col2’:[‘aa~bb~cc~dd’, np.NaN, ‘ii~jj~kk~ll~mm’]}) Col1 Col2 0 a,b,c,d aa~bb~cc~dd 1 e,f,g,h NaN 2 i,j,k,l,m ii~jj~kk~ll~mm The real dataset has shape 500000, 90. I need to unnest these values to rows and I’m using …

Total answers: 4

How to unnest (explode) a column in a pandas DataFrame, into multiple rows

How to unnest (explode) a column in a pandas DataFrame, into multiple rows Question: I have the following DataFrame where one of the columns is an object (list type cell): df=pd.DataFrame({‘A’:[1,2],’B’:[[1,2],[1,2]]}) df Out[458]: A B 0 1 [1, 2] 1 2 [1, 2] My expected output is: A B 0 1 1 1 1 2 …

Total answers: 16