Questions tagged [pandas-melt]

Use this tag for questions related to the pandas.melt or pandas.DataFrame.melt. Be sure to also include the [pandas] tag.

Melt can be used to unpivot a DataFrame from wide to long format.

Useful Canonical:

The documentation:

102 questions
0
votes
1 answer

How do I use pandas melt to flatten out stacked columns into variables

Reading a matrix data with stacked columns in pandas Hello , Newbie to Python here. Need some help in reading xls file with following format as pandas dataframe and writing it as a record xls layout looks like this | SP500 | DJIA | …
0
votes
0 answers

How to pivot Date columns?

I have a dataframe something like this - main dataframe and I need two outputs where I can have the date variables in a single column output1 output2 How do I achieve this ?
Roy Sudip
  • 1
  • 1
0
votes
0 answers

Pandas opposite of melting dataframe

I have a CSV file which I need to perform the reverse of a melt on, the dataframe looks like this: Date/Time Identifier Value 2023-01-01 A 100 2023-01-02 B 75 2023-01-03 A 23 I need to keep the date\time…
berimbolo
  • 3,319
  • 8
  • 43
  • 78
0
votes
2 answers

How to group transpose data in python?

I have a large dataframe like this, instance_id wake_speed_factor wt_E70491_0.857 1,00001 wt_E70492_0.857 0,817721 wt_E70490_0.857 …
PJPATEL
  • 15
  • 6
0
votes
1 answer

Transposing the rows to columns- Python

https://docs.google.com/spreadsheets/d/1ew9_hV30N46zlWKW9Pi-nLM5XxOUUGDbVMRa3FJzEoI/edit#gid=1420260456 Please guide me the process if we can use some pandas functionality like melt/stack to convert into that format. I have reviewed that there are…
0
votes
0 answers

Converting expansive wide dataframe to concise long dataframe efficiently

I have a database that expands horizontally with different lengths. Example Data Database Goal I have a for loop that works and iterates through and appends each set to a new row in a new dataframe, however the data set is growing increasingly…
0
votes
0 answers

Transpose specific columns to rows in Pandas

I have a situation where I would like to transpose a certain set of columns in my dataframe to rows. The columns range which I want to transpose starts from the fourth column till the last column. There are multiple datasets so one of the datasets…
Django0602
  • 797
  • 7
  • 26
0
votes
1 answer

transpose multiple rows to columns with pandas

I have this excel table read in jupyter notebook with pandas. I want to melt the upper row side of the table into column. The table looks like as follow: ori code cgk cgk clg clg …
yangyang
  • 491
  • 4
  • 16
0
votes
2 answers

How to melt multiple columns into one without the column names

I have a pandas dataframe with multiple columns and I would like to create a new dataframe by flattening all columns into one using the melt function. But I do not want the column names from the original dataframe to be a part of the new…
A Newbie
  • 113
  • 8
0
votes
1 answer

Split delimited column into single column

I have a vendor supplied file that stores n medications in a single column separated by ;. I'm struggling trying to melt, then groupby the dateframe. meds = meds.melt(id_vars=['Vendor', 'patientid'], value_name='Medication') meds =…
BP12
  • 27
  • 6
0
votes
0 answers

Rearranging with pandas melt

I am trying to rearrange a DataFrame. Currently, I have 1035 rows and 24 columns, one for each hour of the day. I want to make this a array with 1035*24 rows. If you want to see the data it can be extracted from the following JSON file: url =…
user20050294
0
votes
0 answers

Using melt function for google sheet data

I want to convert columns data to rows in my goggle sheets. Please help me to do this using melt function using jupyter notebook. Also I want updated sheet to be inserted in the same google sheets link but as a new tab. Is there any way to do that?
0
votes
0 answers

Melting a dataframe based on a dependency between columns to be melted and value vars

I am trying to melt a dataframe based on a series of columns which are connected by a time series. The year 2000 y1 is equivalent to the year 2000 y0, 2000 y2 = 2002 y0 = 2001 y1 etc. Consider the raw data import pandas as pd import numpy as np #…
Paddy
  • 91
  • 7
0
votes
1 answer

Melt a Pandas Dataframe with multiple columns

I wanted to know if there's a way to melt a DataFrame with multiple column names. I have this Pandas Data Frame: Edad 2000 2001 2002 2003 ... 2017 2018 2019 2020 ... …
0
votes
1 answer

Pandas divide value and melt Quarter rows into month columns

I have a dataframe like as below df1 = pd.DataFrame({'s_id': [18,23],'SUB':['Phy','Phy'],'Rev_Q1':[80,100],'Rev_Q2':[60,50],'Rev_Q3':[20,12],'Rev_Q4':[10,12]}) I would like to do the below a) Split the revenue from each quarter equally into 3…
The Great
  • 7,215
  • 7
  • 40
  • 128