Questions tagged [wide-format-data]

A data frame is in 'wide format' when it spreads a variable across several columns.

39 questions
4
votes
2 answers

Pandas: transform column names to row values

I'm trying to achieve the transformation below on a pandas DataFrame. The Date columns are essentially being expanded to multiple rows and we get an entry per month instead of one column per month: Source DataFrame: Food Type Eaten…
velxundussa
  • 91
  • 1
  • 10
3
votes
1 answer

Reshaping a dataframe from wide to long format in R using multiple sets of variables

I have a dataset in wide format with participants' information for multiple waves of a survey, including their country, gender, age at interview, and the year and whether they participated in each wave of a survey. Here is a sample of the…
saif
  • 31
  • 1
2
votes
2 answers

Transpose dataframe from wide-to-long with multiple values

I have wide data with multiple values that I need to transpose into a long data table. I've looked at several sites and StackOverflow and cannot seem to find the answer to this, even though its so simple. Some example data: #example data wide <-…
LisaW
  • 23
  • 3
2
votes
2 answers

Mutate value of a range of columns if columns name meets another column value

I have a wide df with columns representing the months of many given years and the changes of colour in each month: df <- data.frame(id = as.integer(c(123,124,125,126)), no_change = as.character(c("May.2010", NA, NA, "Sep.2010")), …
Nao
  • 333
  • 2
  • 11
1
vote
2 answers

Reshape a df from long to wide format using conditional statement

I have a long df that looks like this: df <- data.frame(id=as.integer(c(123,123,123,124,124,124,125,125,126,126,126)), date=as.Date(c("2014-03-12", "2015-05-02", "2015-09-16", "2015-10-24", "2016-12-11", "2017-10-17", "2017-08-06",…
Nao
  • 333
  • 2
  • 11
1
vote
3 answers

Transform table to wide format where not all columns are in long

I'm trying to transform a complex dataframe such as (: olddata_long = A B C SAMPLE_ID 1 2 3 4 5 X1 Y1 Z1 SAMPLE1 G1 H1 J1 K1 L1 X1 Y1 Z1 SAMPLE2 G2 H2 J2 K2 L2 X2 Y2 Z2 SAMPLE1 G3 H3 J3 K3 L3 X2 Y2 Z2 SAMPLE2 …
Gabriel G.
  • 555
  • 1
  • 3
  • 13
1
vote
2 answers

R dplyr solution to pivot categorical matches wider

I feel like this is such a simple thing, but I'm having so much trouble wrapping my head around it for some reason. Say I have a long-format data frame of two categorical variables like so: df <- data.frame( table_name = c("tbl1", "tbl1", "tbl1",…
1
vote
1 answer

Using the default and specifying the same default value explicitly give different results in pd.wide_to_long

I was reshaping a DataFrame from wide to long format. However I get different results in two cases which should be identical - see below import pandas as pd import numpy as np d_test = pd.DataFrame({"id": [1,2,3,5], "q1": [1,4,4,2], "q2":…
P.Jo
  • 532
  • 3
  • 9
1
vote
1 answer

Convert wide format data (separate dfs) to long format using Python

Convert wide format data in separate dfs to long format in a single df in Python. Some values are NaNs. Minimal example: df1 = pd.DataFrame({ "id": ["Mark", "Dave", "Ron" ], "c2_A": [2, 3, np.nan ], …
AAA
  • 332
  • 1
  • 10
1
vote
2 answers

transform two matching data sets to long format and join with row variables

I have an experimental predict method for the nestedLogit package that generates predicted probabilities and their standard errors for a polytomous response. Both the fitted probabilities and standard errors are returned as matrices. For plotting,…
user101089
  • 3,756
  • 1
  • 26
  • 53
1
vote
1 answer

Make dataset wide format for entries falling within a certain date interval

I am trying to figure out how to make multiple customer orders placed within 120 days wide format for each customer. If a customer has orders placed over the course of several year, then there are multiple intervals of 120 days, so each customer may…
pandas123
  • 125
  • 10
1
vote
1 answer

How to transform long to wide data, while adding extra rows with values from further columns

I have been looking for a solution to my problem but have not been successful. I assume because it is an uncommon wish in terms of data analysis, good practice, and how to properly store data. I need the data in the specified format for further…
Bacillus
  • 47
  • 6
1
vote
3 answers

How to convert a wide format data with multiple categorical variables to long format in R?

Here is my initial data. df <- data.frame(v1 = c("a", "a", "a", "a", "a", "a"), v5 = c("c1", "c2", NA, "c1", "c2", NA), v6 = c(20, 30, NA, 14, 26, NA), v7 = c("d1", "d2", "d3", "d1", "d2", "d3"), …
Joy
  • 21
  • 2
1
vote
1 answer

Animate px.line line with plotly express

Learning plotly line animation and come across this question My…
Kai Zhang
  • 155
  • 1
  • 9
1
vote
1 answer

R: How to transform long longitudinal data to wide longitudinal data, when I only have the age (in days) as an indicator of measurement time?

I have a long-formatted set of longitudinal data with two variables that change over time (cognitive_score and motor_score), subject id (labeled subjid) and age of each subject in days at the moment of measurement(labeled agedays). Measurements were…
1
2 3