Questions tagged [pandas-explode]

Questions relating to the explode method of pandas DataFrames or Series. Be sure to also include the base tag [pandas].

The explode method was added in pandas 0.25.0 (July 18, 2019).

explode transforms columns of list-like values so that each element is on its own row. By default, index values will be duplicated for these rows. Moreover, for the case of DataFrame.explode, the values in the columns that are not to be exploded will also be duplicated.

Useful Canonicals:

The Documentation:

60 questions
0
votes
2 answers

how to use pandas function with condition, here are using .explode as example

My df: C1 C2 C3 A True [a,b,c] A False [a,b,c] B True [a,b,c] B False [a,b,c] What I want is, only apply .explode on C3 when C1 == A and C2 == True. How can I get to my expected result: C1 C2 C3 A True a …
0
votes
0 answers

exploding on column creates not only rows but also columns

my df has a column names_text which is a list of lists. I want transform the lists within names_text into rows. I want each list within the nested lists in column names_text to form a unique row. Representative data: d = [['aa', None, 'xx', [['ps',…
id345678
  • 97
  • 1
  • 3
  • 21
0
votes
0 answers

Transform list of lists as rows pandas dataframe

Ultimately i want each list within the nested lists in column names_text to form a unique row in the dataframe. Code: data = [] . . . text = ' '.join(map(str, raw_text)) ### create list of names …
id345678
  • 97
  • 1
  • 3
  • 21
0
votes
0 answers

Canonical way to do a multi-column explode in pandas > 0.25.0, < 1.3.0?

I have this data set, in which there is a uid field which is a list of integers, and another array which is a list of booleans that corresponds to the uid fields. I'd like to turn this array records into long records instead, exploding on /2/…
Mittenchops
  • 18,633
  • 33
  • 128
  • 246
0
votes
1 answer

Expanding Records Based On Date Range Pandas

I am attempting to expand the records in a data frame between two dates. Given the input file of single entry for each record, I want to expand it based on a given date. Here is an example of the input: Here is an example of the desired expanded…
jn1351
  • 53
  • 7
0
votes
1 answer

explode the pandas nested array in python

I am reading data from MongoDB and dropping in s3. Reading the data using Athena. This is my collection which contains Items columns which is an array. How to explode that into separate columns when saving that to…
0
votes
2 answers

Python Dataframe Explode Rows with multiple values

I am sorry to replicate the same question which was answered before but they don't seem to give me the desired outcome, maybe I missed something. I have a subset of the Stack Overflow dataset like the following: **tags …
0
votes
3 answers

How to do explode and keep a fair proportion of number value for each new row Pandas

I have this dataframe: A B 0 [0, 1, 2] 1 1 foo 1 2 [3, 4] 1 I would like to use explode function for column "A" and then to keep right and fair proportion for each exploded row in case with column "B" . So the result…
kvetjo
  • 55
  • 4
0
votes
2 answers

Explode rows pandas dataframe

I have a pandas dataframe like the below: Letters Date 'Letters : a' 2021 'Letters : a,b,c' 2019 'Letters : a,b' 2017 I want to be turned into the below, using…
Dim Tsi
  • 25
  • 5
0
votes
2 answers

how to solve pandas multi-column explode issue?

I am trying to explode multi-columns at a time systematically. Such that: [ and I want the final output as: I tried df=df.explode('sauce', 'meal') but this only provides the first element ( sauce) in this case to be exploded, and the second one…
hilo
  • 116
  • 11
0
votes
2 answers

How to explode pandas dataframe with lists to label the ones in the same row with same id?

For example, I have a pandas dataframe like this : Ignoring the "Name" column, I want a dataframe that looks like this, labelling the Hashes of the same group with their "ID" Here, we traverse each row, we encounter "8a43", and assign ID 1 to it,…
Chintan Mehta
  • 129
  • 1
  • 9
-1
votes
3 answers

input to function explode should be array or map type, not struct

I have the following data. data = [ [ "2022-12-12", ["IND", "u1", [["auction_1", [[1,20], [2,12]]], ["auction_2", [[1,5], [2,7]]]]], ], [ "2022-12-12", ["USA", "u2", [["auction_1", [[1,8], [2,12]]],…
Rahul
  • 1,858
  • 1
  • 12
  • 33
-1
votes
1 answer

exploding a multi dictionnary columns

I have a data that contains +15 columns all of them with dictionnary as values. all of the dictionnary has the same keys but different values depending on th column and the key of course. i need to explode them into on data that has the keys as…
-1
votes
1 answer

How to explode a struct index in pandas series

I have a pandas Series where the index is a StructType. I want to explode this index into the structfields. index value (2005-07-03, beta0) 0.997160 (2005-07-03, beta1) 0.037629 (2005-07-03, beta2) 0.037629 (2005-07-03,…
-2
votes
1 answer

How to explode Python Pandas Dataframe and merge strings from other dataframe?

Dataframe1 has a lot of rows and columns of data. One column is Text. Certain rows in Text column have strings and some strings include within the strings this {ExplodeEList2} How to explode (expand) those specific rows of Dataframe1 and replace…
user1574881
  • 91
  • 1
  • 6
1 2 3
4