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

Having issues with melt in R

So the data looks like this at present. The mean column is average hourly wage. The meanann is average annual wage hence the ann at the end. Entry follows the same logic. However, trying to make it look like the intended result below ID mean…
Tim Wilcox
  • 1,275
  • 2
  • 19
  • 43
0
votes
0 answers

R: Prevent melt from rounding to 2 decimals when reshaping tibble

I have a tibble (called bidrag) which i want to reshape using melt(bidrag, id.vars=c("YYYYMMDD")). However, this somehow results in all my values being rounded to 2 decimals and I need at lease 5. > bidrag # A tibble: 369 x 8 YYYYMMDD…
Kenno
  • 1
0
votes
2 answers

How can I melt a matrix data frame in R with 2 variables and 1 value column?

My data looks like this: col1 col2 col3 col1 100 25 30 col2 25 200 50 col3 30 50 300 where the column and row names are c("col1", "col2", "col3") I want it to look like this: Var1 Var2 Value col1 col1 100 col1 col2 25 col1 col3…
0
votes
2 answers

Regarding grouping in ggplot in R

I have this data frame and I want to group expected column with different individual patient data. I wrote the code but it works for 1 patient only. I wanted to do this for 14 patients. As shown in figure this graph is for 1 patient and I have to…
Micky
  • 55
  • 6
0
votes
1 answer

How to melt the pd.DataFrame to organize the data? (toy example included)

Issue I am curious to know how to melt the data_df in the toy example provided below to the desired_df. import pandas as pd data_df = pd.DataFrame(data = [['FR','Aug',100], ['FR','Sep',170], ['FR','Oct',250], …
Eiffelbear
  • 399
  • 1
  • 4
  • 23
0
votes
1 answer

Get long format in a special way

I have a dataset that is quite in a wide-format and I want it to be in a long format. Usually I use melt for that cases but here I don't know if this will work. That's my dataset: > Data <- + data.table( + ID = 1:6, + N1 =…
TobiSonne
  • 1,044
  • 7
  • 22
0
votes
1 answer

How to Melt data shape in custom format in python pandas?

I have below database format stored in a pandas dataframe ID Block MGKfdkldr Product 1 MGKfdkldr Product 2 MGKfdkldr Product 3 GLOsdasd Product 2 GLOsdasd Product 3 NewNew Product 1 OldOld Product 4 OldOld Product…
0
votes
2 answers

Based on long-format date column in a data.table, reduce cols in wide-format data.table

I have a wide-format data.table like so: library(data.table) dt_wide <- data.table( "id" = seq(1:10), "yw_1001" = trunc( runif(10,0,100) ), "yw_1002" = trunc( runif(10,0,100) ), "yw_1003" = trunc( runif(10,0,100) ), "yw_1004" = trunc(…
epiNS
  • 353
  • 2
  • 7
0
votes
0 answers

Pivot table in Pandas to "unmelt" values in specified column into individual columns

I have a Pandas data frame: timestamp device_id metric_name metric_value 2020-10-20 6C0301 throughput 5.0 2020-10-21 6C0301 throughput 6.3 2020-10-20 6C0301 cache 4.7 2020-10-21 6C0301 cache …
Cybernetic
  • 12,628
  • 16
  • 93
  • 132
0
votes
1 answer

Melting a sparse matrix (dgCMatrix) and keeping its zeros

I have a large sparse matrix (a Matrix package dgCMatrix object in R). Toy example: m <- Matrix(c(0,0,2:0), 3,5) rownames(m) <- paste0("g",1:3) colnames(m) <- paste0("c",1:3) > m 3 x 5 sparse Matrix of class "dgCMatrix" c1 c2 c3 c4 c5 g1 . 1 .…
dan
  • 6,048
  • 10
  • 57
  • 125
0
votes
1 answer

How to efficiently melt multiple columns using the module melt in Pandas?

The objective is to unpivot the following table Activity General m1 t1 m2 t2 m3 t3 0 P1 AA A1 TA1 A2 TA2 A3 TA3 1 P2 BB B1 TB1 B2 TB2 B3 TB3 into the following format Activity General M Task 0 P1…
mpx
  • 3,081
  • 2
  • 26
  • 56
0
votes
1 answer

melt/Pivot in python dataframe

I am trying to convert Input data frame to output data frame, but code is not working properly, not sure where am I missing. What I tried: I tried to use pandas.pivot(index, columns, values) function but its showing me error not sure where I am…
0
votes
0 answers

complex transposing using Reshape function from Wide to Long

i would like to re shape merged file , below it the input table. library(readr) df2 <- read_table2("February February February February February February February February February February February February …
Aditya
  • 13
  • 5
0
votes
2 answers

combine melt and groupby on pandas df

I have a df that looks like this country country_abbr region year v1 v2 v3 ... v100 India IN IND 1999 327.0 7058.0 8856.0 ... 7900.0 Saint Lucia LC LCA 1990 NaN NaN NaN ...…
LMGagne
  • 1,636
  • 6
  • 24
  • 47
0
votes
0 answers

seaborn multiple boxplot based on multiple assignments

Hello I have a dataframe that's assigned with two labels sample and campaign: import numpy as np var=np.random.sample(4) sample = [1,1,2,2] campaign = [1,2,1,2] d = pd.DataFrame([var, sample, campaign]).transpose() d.columns =…
Hud
  • 301
  • 1
  • 12