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
1 answer

How can I unpivot data with multiple columns and multiple variables in pandas?

How can I unpivot data with multiple columns and multiple variables in pandas? my input: And desire output:
0
votes
1 answer

Change columns names to a row variable in Pandas

I´m importing an excel file with column names in merge cells. When I create a pandas data frame what I have is something like this: |------|------|------|------|------|------|------|------|------| | | | | A | A | B | B | …
LizUlloa
  • 172
  • 3
  • 9
0
votes
1 answer

how to reverse a dataframe to its original form in pandas

i have data frame and used the command pd.pivot_table(df,columns="category",index=["year","period"]) did some data processing at this dataframe and i want to reverse the process to get the original formation of the df. i tried with pd.melt and…
Willzyx
  • 1
  • 1
0
votes
1 answer

MLT transparency of watermarks and tracks not working

I am trying to get melt to work, but it seems, it doesn't support transparency (alpha channels)! Using the official watermarking example, I get a black background behind the PNG and don't see any video through. melt \ test.mp4 out=1000 \ -track…
tobidude
  • 480
  • 1
  • 7
  • 11
0
votes
1 answer

How to use vector of strings in measure.vars in melt in R?

I have a data.csv file as: BBBB, B, OOB CCCC, C, OOC DDDD, D, OOD EEEE, E, OOE I obtained the 2nd column as: df1 <- read.csv(data, header=FALSE,strip.white=TRUE,stringsAsFactors=FALSE)[2]. The question is how can I use the df1 as c("B",…
Debian
  • 13
  • 1
0
votes
1 answer

Python - Transform DataFrame for Merge

I have two different dataframes. One looks like: Date StoreID MerchandiseType Count 04/01/2020 1 Hat 2 04/01/2020 1 Shirt 4 The other looks like: Date …
dcrowley01
  • 141
  • 2
  • 12
0
votes
0 answers

Is the melt function the right function to use? I want to reorganize my columns and rows in R

I was hoping to get some help reorganizing my data table. Right now I have a data table that looks something like this (this is fake data): city year income_per_capita Boston 1998 21344.32 Boston 1999 23454.45 Boston …
imdinos
  • 49
  • 5
0
votes
1 answer

Wide to long multiple rows and only two variables

I've searching but haven't find the answer. I have the next dataframe Pais Anio Electricidad Electricidad Electricidad Electricidad Electricidad Electricidad Electricidad Electricidad Electricidad Electricidad Electricidad 0…
Roger Nieto
  • 63
  • 10
0
votes
2 answers

Retaining column information when melting multiple columns into one

I have a data.table which I have melted follows: library(data.table) DT <- fread( "ID country year Event_A Event_B 4 NLD 2002 0 1 5 NLD 2002 0 1 6 NLD 2006 1 1 7 NLD 2006 1 0 8 NLD 2006 1 1 9 GBR 2002 0 1 10…
Tom
  • 2,173
  • 1
  • 17
  • 44
0
votes
3 answers

Convert data from wide to long format keeping all alternatives of the dv and adding a choice variable

I try to get my data to work with the mlogit-package in r. I failed in converting the wide data format to a long format with the mlogit.data command, so I tried it by myself using melt. This is what I have so far (case is a case identifier, dv will…
0
votes
1 answer

Python pandas custom unmelt - create columns from duplicated rows

I have the following dataframe: import pandas as pd import numpy as np base_df = pd.DataFrame({ 'id': [1,2,3], 'base_value': [100, None, 123.1] }) id base_value 1 100.0 2 NaN 3 123.1 There's also another one: extended_df =…
balkon16
  • 1,338
  • 4
  • 20
  • 40
0
votes
0 answers

pandas long to wide: melt + transposing

I have this dataframe: np.random.seed(0) df = pd.DataFrame({"Status": np.random.choice(["Married", "Single", "Single", "Single", "Widow"], 10000), "Genre": np.random.choice(["Masculine", "Masculine", "Masculine", "Femenine"], 10000), …
Chris
  • 2,019
  • 5
  • 22
  • 67
0
votes
0 answers

Melting Dataframe with multi levels and specific Index

I have a dataframe with 2 levels that looks like this : dataframe input I would like to melt this dataframe so it would look like this : dataframe desired I tried using melt but I am not able to make appear the columns "Mass" and "Energy". I don't…
Joris
  • 1
0
votes
3 answers

Transposing all but the first column in a dataframe

I have got the following dataframe df = pd.DataFrame({'ISIN': ['A', 'B', 'C'], 'Jan': [40000, 50000, 42000], 'Feb': [40000, 50000, 42000], 'Mar': [40000, 50000, 42000]}) Which produces …
harrison10001
  • 109
  • 1
  • 6
0
votes
1 answer

How to iterate through excel sheets and unpivot dataframes. Then append them together into one daraframe

I have Excel with 3 sheets: Gross, Margin, Revenue. Each of them has a table with same columns and row headers. I need to : 1) iterate through each sheet and save into a dataframe 2) unpivot each dataframe 3) append value columns from each…
Serdia
  • 4,242
  • 22
  • 86
  • 159