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
2
votes
2 answers

reshape a dataframe R

I am facing a reshaping problem with a dataframe. It has many more rows and columns. Simplified, it structure looks like this: rownames year x1 x2 x3 a 2000 2 6 11 b 2000 0 4 2 c 2000 0 3 …
refroll
  • 131
  • 1
  • 9
2
votes
2 answers

Referencing x axis variable from a melted data frame to plot using ggplot2 in R

I have a data frame df with 10 columns such as this, row.names c(300, 400, 500, 600, 700) X1 X2 X3 X4 X5 X6 X7 X8 X9 1 absTLM_3_4 300 -4.147782e-08 -3.360635e-08 -3.306786e-08 -3.133482e-08 -3.124207e-08 -3.056317e-08 …
Amm
  • 1,749
  • 4
  • 17
  • 27
2
votes
1 answer

Why is dcast populating my (melted) dataframe with NAs?

I began with this innocuous dataframe: Date Company Jobs 1/1/2012 Company 1 12 1/1/2012 Company 2 84 1/1/2012 Company 3 239 1/1/2012 Company 4 22 I am dreaming, begging, and fantasizing about this…
tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
1
vote
1 answer

Converting wide data to long when labels need to be manually specified

I have the following dataframe: data = {'POSTING_AMOUNT1': [10,20,30], 'POSTING_AMOUNT2': [100,200,300], 'POSTING_AMOUNT3': [15,25,35], 'POSTING_AMOUNT4': [20,40,60]} My expected output needs to be as…
Rip_027
  • 201
  • 2
  • 11
1
vote
1 answer

Convert table DT1 to DT2 fill with binary using data.table

I have DT1 and try to convert this table to DT2 with 1,0 DT1<-fread("variable bf_target_N bf_comparator_N drugA 2 1 drugB 3 4 drugC 4 5 ") DT2<-fread("type drugA drugB drugC bf_target_N 1 1 1 bf_target_N 1 1 …
zell kim
  • 69
  • 5
1
vote
2 answers

Pandas: Pivot a table using the column names as variables

I have a dataset in which each column represent a different measurement for a specific parameter. The parameter name is the column name. I have the following sample code: df=pd.DataFrame({'A': (1,2), 'B':(3,4)}) display(df) A B 0 1 3 1 2…
Pablo
  • 167
  • 2
  • 9
1
vote
2 answers

Transform a table of two columns (attributes and description) to multiple columns where each column is an attribute: using PANDAS

I currently have a table like this: ATRIBUTE DESCRIPTION CODIGO A1 TITULO A2 AUTOR A3 SUMARIO A4 CODIGO B1 TITULO B2 AUTOR B3 SUMARIO B4 EXTENSION B5 CODIGO C1 AUTOR …
PAstudilloE
  • 659
  • 13
  • 24
1
vote
3 answers

Reshaping a Dataframe with repeating column names

I have data that looks like this: dataframe_1: week SITE LAL SITE LAL 0 1 BARTON CHAPEL 1.1 PENASCAL I 1 1 2 BARTON CHAPEL 1.1 PENASCAL I 1 2 3 BARTON CHAPEL 1.1 PENASCAL I 1 And, i need…
user2100039
  • 1,280
  • 2
  • 16
  • 31
1
vote
2 answers

how to divide text after symbol into rows in pandas

im trying to divide text from each symbol from one long text. Column 1 C9 ban Pearl; LEV ban Fracture; C9 pick Lotus; LEV pick Haven; C9 ban Split; LEV ban Ascent; Bind remains and i need to tranform this long text into this…
Octa
  • 49
  • 8
1
vote
2 answers

Complicated pandas dataframe melt

I have an excel worksheet that has some data in the following format: Unnamed: 0 Unnamed: 1 Unnamed: 2 Unnamed: 3 Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Unnamed: 9 Unnamed: 10 Unnamed: 11 Unnamed: 12 0 Hour 1 FI NO2…
Tom
  • 109
  • 9
1
vote
3 answers

Reshaping a table, melting and pivoting with duplicate entries

import pandas as pd data = [['4/04/2023','Floors','Tables','Roof','Paint','Paint'],['4/05/2023','Roof','Floors','Tables','Roof','Paint'],['4/06/2023','Paint','','Floors','Tables','Roof'],['4/07/2023','Roof','Paint','','Floors','Tables']] df =…
James C
  • 55
  • 4
1
vote
2 answers

dcasting long table along multiple columns

I am having a difficult time understanding dcast, and cannot get the right commands to get what I want. I will give a minimal repro. #generate the data ID <- c('a','a','a','b','b','b') Parameter <- c('p1','p2','p3','p1','p2','p3') Value <-…
1
vote
2 answers

convert wide table to long in R

I have a dataset that look something like this: groupA <- rbinom(n=50,size=1,prob=0.5) groupB <- rbinom(n=50,size=1,prob=0.5) groupC <- rbinom(n=50,size=1,prob=0.5) groupD <- rbinom(n=50,size=1,prob=0.5) dtTest <- cbind(groupA, groupB, groupC,…
Nneka
  • 1,764
  • 2
  • 15
  • 39
1
vote
5 answers

Column Pair-wise aggregation and reorganization in Pandas

I am importing a csv file into a pandas dataframe such as: df = pd.DataFrame( {0: {0: 'ID', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5'}, 1: {0: 'Net Cost', 1: '30', 2: '40', 3: '50', 4: '35', 5: '45'}, 2: {0: 'Charge Description', 1: 'Surcharge A', 2:…
sebwallat
  • 65
  • 3
1
vote
1 answer

pyjanitor pivot_longer multiple sets of columns with common grouping variable and id column

Follow-up from my last question: regex column selection inside pd.melt function I used the following code to pivot_longer columns that match the string "rating". import pandas as pd import janitor (df .pivot_longer( column_names = "*rating", …
prayner
  • 393
  • 1
  • 10