Questions tagged [data-wrangling]

1242 questions
0
votes
1 answer

Wide to long, combining columns in pairs but keeping ID column - R

I have a dataframe of the following type ID case1 case2 case3 case4 1 A B C D 2 B A 3 E F 4 G C A 5 T I need to change its format, to a long shape, similar as the below: ID col1 col2 1 A B 1 A C 1 A D 1 …
Carrol
  • 1,225
  • 1
  • 16
  • 29
0
votes
2 answers

Mutate ifelse to replace values in r

I have a data frame that looks like the below: Word Value1 Value2 Apple True True Chair True False nonWord False False Hat False True ... ... I'm attempting to change all the values of nonWords to NA's. data…
psychcoder
  • 543
  • 3
  • 14
0
votes
2 answers

Melt using tidyverse (dplyr) functions, when needing `measure = patterns("x", "y")` from data.table

I have a nice and quite long pipe of different tidyverse commands, but halfway through I need to use a SetDT() %>% melt(...) %>% as_tibble(). My code works fine, but I was wondering if a pure tidyverse solution using either gather() or…
L Smeets
  • 888
  • 4
  • 17
0
votes
0 answers

Python Index Error Assistance, Newbie to data wrangling

GOAL: To turn my results that are in list format into a data frame that I can print. I have an index error, I tried to change the index numbers...but I don't think that is the underlying issue. Assistance would be much…
0
votes
1 answer

How to reshape data in Pandas DataFrame

I am working on a project where i need to reshape the data in particular Format. I have transformed successfully in Excel but how we can transformed this Data with pandas because in Excel we have the limitation of rows. Territory ID Patient Id …
0
votes
1 answer

How do I group together all possible values of a set of discrete variables in R?

I have a data frame with five dichotomous predictor variables, one dependent dichotomous variable, and a column of predicted probabilities: F1 F2 F3 F4 F5 Pred_Prob 1 A D E G I 0.25 2 B C F H J 0.3 3 A C E G I 0.9 4 B…
Namenlos
  • 475
  • 5
  • 17
0
votes
1 answer

Using pivot on pandas introduces unwanted NaNs

I'm doing some basic data wrangling and counting the number of True's and False's that each version has in the data below. Here's my pandas dataframe (df): version type count 0 A False 80 1 A True 11 2 B False…
psychcoder
  • 543
  • 3
  • 14
0
votes
1 answer

How to re-order the columns after splitting it?

I have a data frame that contains the list of countries and it has been split using the csplit function. The code is as follows:- df <- data.frame(country = c("India, South Africa", "United Kingdom, United States, India", …
Sri Sreshtan
  • 535
  • 3
  • 12
0
votes
1 answer

R Make a conditional column based on conditional row

I have a dataset that has long format BUT with row separation like this example