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

How can I use row index values as column for dataframe?

So, I collected data from 21 participants with 16 EEG channels and I extracted the Gamma band. My current dataframe looks like this ([336 rows x 2 columns]): Channels Gamma Fp1 0.345908 Fp2 0.121232 F3 0.213212 ..... .... Now I…
1
vote
1 answer

Reshape data table from wide to long with transpose

I have a dataset (Sample_pH): Head(Sample_pH) Mill Acid `1_day` `3_days` `1_week` `2_weeks` `4_weeks` `2_months` `3_months` `6-7_months`
Nanna
  • 73
  • 8
1
vote
1 answer

How to handle duplicated or blank columns and add number in duplicated ones in python dataframe?

Dataframe has 200+columns with repeated dates and empty columns weight height total weight height total 2019 2019 2019 2020 2020 2020 Species jan1 jan1 '' jan1 jan1 '' cat 1.0 2.0 3 4.0 …
vishvas chauhan
  • 229
  • 1
  • 12
1
vote
2 answers

Reshape dataframe using pandas melt to get two value columns

my data is in the following format x = pd.DataFrame([ {'date': '2011-01-01', 'col1': '1','col2': '5', 'A_Q': '1', 'A_W': 'aa', 'B_Q': '2', 'B_W': 'zz'}, {'date': '2011-01-02', 'col1': '1','col2': '9', 'A_Q': '-1', 'A_W': 'bb', 'B_Q': '3',…
MRTN
  • 101
  • 1
  • 4
1
vote
1 answer

How can I add labels to bar chart with ggplot2 if using a melted data.table?

I am using a melted data.table: cat <- melt(as.data.table(insti), id.vars=c(1:3,11), measure.vars=4:10) which I used to create a plot: ggplot(cat, aes(x=reorder(Llengua, -Publicacions), y=Publicacions, fill=Xarxa))+ …
1
vote
0 answers

How to multiple rows are melted in R?

I have a data set. structure(list(X = c("ID", NA, "TOM", "TOM", "TOM", "TOM", "TOM", "JAY", "JAY", "JAY", "JAY", "JAY"), X.1 = c("number", NA, "1", "1", "1", "1", "1", "2", "2", "2", "2", "2"), X.4 = c("10/1", "1", "a", "a", "a", "a", "a", "a",…
Yun
  • 89
  • 6
1
vote
1 answer

R: Melt dataframe by 1 column and stack the other columns that have the same name patterns

I have this simplified data situation: df <- data.frame(Year = 1:3, A.x = 4:6, A.y = 7:9, A.z = 10:12, B.x = 4:6, B.y = 7:9, B.z = 10:12, …
Theodore
  • 13
  • 4
1
vote
3 answers

Pivoting without numerical aggregation/ a numerical column

I have a dataframe that looks like this d = {'Name': ['Sally', 'Sally', 'Sally', 'James', 'James', 'James'], 'Sports': ['Tennis', 'Track & field', 'Dance', 'Dance', 'MMA', 'Crosscountry']} df =…
1
vote
3 answers

How to Transpose Repeating Columns to Rows Pandas

I have a df1 that looks like this: year site 1 2 3 year site 1 2 3 year site 1 2 3 year site 1 2 3 1991 A 4.1 5.9 4.1 1991 B 3.3 4.1 4.1 1991 C 4.1 0.6 4.1 1991 D 4.1 4.1 4.1 1992 …
user2100039
  • 1,280
  • 2
  • 16
  • 31
1
vote
2 answers

Cleaning Excel File Using Pandas

I have an excel file which I've read using Pandas the output is as follows: +------------+-----+-----+-----+ | Type | 1 | 2 | 3 | | Category | A | A | C | | Dates | NaN | NaN | NaN | | 01/01/2021 | 12 | 12 | 9 | |…
Lopez
  • 461
  • 5
  • 19
1
vote
2 answers

Convert column and sub column into row

I have below data in an Excel file with column marks & sub column $ | Marks | ______________________ Student | $ |% |# | ______________________ Joy | 7 |2 |0 | RED | 9 |2 |5 | CTL | 5 |0 |4 | I want to convert column…
1
vote
3 answers

Combine two dfs with different column names and then melt

I want to combine two data frames but melt them into different columns based on…
GIS_newbie
  • 35
  • 4
1
vote
2 answers

Turn specific row values into columns using R

I have a dataset similar to the one listed below v1 <-c('name1','0/0','0/1','1/1','name2','0/0','1/1','name3','0/0','0/1','1/1','name4','0/0','0/1','1/1','name5','0/0','1/1') v2 <- c(NA,95,3,2,NA,98,2,NA,93,5,2,NA,94,3,3,NA,96,4) df <-…
Joe
  • 11
  • 2
1
vote
2 answers

Reshaping multiple long columns into wide column format in R

My sample dataset has multiple columns that I want to convert into wide format. I have tried using the dcast function, but I get error. Below is my sample dataset: df2 = data.frame(emp_id = c(rep(1,2), rep(2,4),rep(3,3)), Name =…
hk2
  • 487
  • 3
  • 15
1
vote
2 answers

How to use pandas melt for several columns without set pattern

I have a dataframe like as shown below df =…
The Great
  • 7,215
  • 7
  • 40
  • 128