Questions tagged [melt]

In R, the "melt" function from the "reshape2" and "data.table" (and earlier, "reshape") packages converts data into a long form. Melt is also a web application framework written in PHP.

In data processing, reshaping data to a long form where each row represents only one observation of one variable is often called "melting" the data, similar to UNPIVOT in some relational databases such as .

In , the function is part of the and packages (earlier, the "reshape" package).

This functionality is also found in similar data processing tools such as .

Related tags:

840 questions
1
vote
1 answer

Rearrange data and create time based line graph - R

I have a dataset where each row is an object, that is grouped into different alphabetical groups. This data set also has the price and the time the price was set at. I want to create a line graph where I have time on the x-axis, price on the…
imdinos
  • 49
  • 5
1
vote
2 answers

Structure data for 2x2x2 ANOVA in R

I have the following dataset, of which a subset is: structure(list(Sex = c("Male", "Male", "Female", "Male", "Male", "Male" ), AgeGroup = structure(c(2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Young", "Old"), class = "factor"), FPT_Values_LEFT =…
CanyonView
  • 401
  • 3
  • 15
1
vote
1 answer

Pandas pivot heatmap filter most frequent values

Basically, my final result should be a heatmap of the X most preferred destinations by the X most common origin countries (like R question How to create heatmap only for 50 highest value here). Let's say x=2 to align with the small toy dataframe…
Papayapap
  • 212
  • 2
  • 12
1
vote
1 answer

Converting dictionary to dataframe, and then melting / stacking columns to rows

I am a bit confused about how to use melt or stack correctly in order to transform my dataframe. Currently have a dataframe which looks as follows: My objective is to transform this data frame, (probably using melt or stack), and I'm having some…
Gary
  • 2,137
  • 3
  • 23
  • 41
1
vote
1 answer

Pandas: Wide to first, second, third, identified categories

I am wondering if anyone knows a quick way in pandas to pivot a dataframe to achieve the desired transformation below. It is sort of a wide-to-long pivot, but not quite. Input Dataframe structure (needs to be able to support N number of categories,…
1
vote
3 answers

how to melt the column with group by in python

I have data with 4 columns . I want to perform group by with melt. data: col1 col2 col3 col4 de1 do1 2020-11-24 vt1 de1 do1 2020-11-24 vt2 de1 do2 2020-11-24 vt1 de1 do2 2020-11-24 vt2 I…
Navya
  • 307
  • 3
  • 15
1
vote
1 answer

stacking multiple columns into single column with single value in R

ID Time U1 U2 U3 U4 1 20 1 0 0 0 2 20 0 1 0 0 3 20 0 0 1 0 4 20 0 0 0 1 And I would need to keep it like: ID Time U 1 20 U1 2 20 U2 3 20 U3 4 20 U4 I tried with: X_D <-…
zara
  • 13
  • 3
1
vote
2 answers

Efficiently Reshape Pandas Dataframe with Equivalent Variable

I'm struggling with reshaping a pandas data frame. Basically, I'm experimenting with sports statistics and I'm trying to tidy up box scores. I have a data frame which has visitor team and home team listed, along with their scores, all in unique…
1
vote
2 answers

How to re-arrange a dataframe creating four continuous variables from two ones and a third cathegorical variable with two levels?

I have next dataframe: df <- data.frame(Date= as.Date(c("2020-08-04","2020-08-04","2020-08-06","2020-08-06","2020-08-07","2020-08-07")), Period= c("Day","Night","Day","Night","Day","Night"), State.1= c(1,…
Dekike
  • 1,264
  • 6
  • 17
1
vote
2 answers

Get corresponding value for particular index/key in Pandas after converting wide to long

I am planning to implement the below logic to get the student score. Find students getting more than 60 marks And then get that student marks too based on Subject Student Key! Input Data data = [['Maths', 100,80,20], ['Science', 80,20,10]] df =…
Sam
  • 336
  • 6
  • 16
1
vote
1 answer

Is there a function within dcast that allows me to include additional conditions?

I'm trying to create a wide format dataset that would include only some of the long format data. This is data from learners going through an online learning module in which they sometimes get "stuck" in a screen, therefore have multiple attempts…
1
vote
1 answer

python pandas loops to melt or pivot multiple df

I have several df with the same structure. I'd like to create a loop to melt them or create a pivot table. I tried the following but are not working my_df = [df1, df2, df3] for df in my_df: df = pd.melt(df, id_vars=['A','B','C'], value_name =…
Matteo
  • 165
  • 1
  • 11
1
vote
2 answers

Values change when melting numeric column headers using reshape package

I have a dataframe that looks like…
1
vote
2 answers

Transposing a dataframe and using the first column as an index

I have a dataframe that is structured like below, where A/B/C/D are different treatment methods: input <- read.table(text=" filename wavelength A B C D file1 w1 NA NA 1 2 file1 w2 NA NA 3 2 file1 w3…
Mulligan
  • 85
  • 7
1
vote
1 answer

restructure large data frame with multiple data types

I'm struggling to get my data (xlsx file) in the correct shape. My original database is as follows: patient when age weight height watchID dateFrom 1 T01 pre …
Ztarrk
  • 13
  • 2