All Questions
133
questions
0
votes
0
answers
43
views
Is there a more effective way to create new columns from row values in a Pandas DataFrame? [duplicate]
Given a dataframe with three initial columns, one of which has categorical type with two categories, the aim is to create distinct columns for each category and subsequently store within them the ...
4
votes
3
answers
107
views
Sum up replicate columns in dataframe, keep rows unique
I thought this would be a relatively easy task to do but I couldn't find examples here that weren't focused on summing up rows based on column conditions. What I'm trying to achieve is to sum up ...
0
votes
0
answers
24
views
how dcast melted data winto a table with header and sub-header?
I have Input data like the one below and I want to know if there is any way to reshape it into an Excel format with a header and sub-header.
Input:
Cons rep name value
10 N=1 A 12
...
3
votes
3
answers
96
views
Is it possible to reorder a table in R?
I have a table as belowe:
dput(df)
structure(list(Samples = c("Cont-4", "Cont-4", "Cont-4", "Cont-4",
"Cont-4", "Cont-4", "Cont-4"...
0
votes
1
answer
29
views
How do I make tidy data from rows of observations? [duplicate]
I want to make a ggplot boxplot and I think I need to format my data from this:
markerID V1 V2 V3
1 0.8636364 0.8409091 0.7954545
2 0.8863636 0.8409091 0.8409091
to ...
1
vote
1
answer
47
views
function for reshaping data efficiently
I need to reshape a dataframe that looks like:
holdc
country_n popClass_n org P50M P50L P50U P95M P95L P95U P99M P99L P99U P99_9M P99_9L P99_9U
1 Austria Adults ADG 0.0445 ...
0
votes
2
answers
52
views
long to wide table on multiple columns in r [duplicate]
I'm having trouble in transform my table from long to wide. Table like :
Con Bro Gr N Freq
Jp CF ii 578 54.3
Jp CF ir 423 45.7
Jp CY im 1835 69.4
Jp CY nm ...
1
vote
1
answer
106
views
Create OHLC Bars From Dictionaries - Websocket Stream
I am connecting to a websocket that sends messages in this format:
msg = {'ev': 'A', 'sym': 'SPY', 'v': 222, 'av': 107783639, 'op': 391.841, 'vw': 396.45, 'o': 396.45, 'c': 396.45, 'h': 396.45, 'l': ...
0
votes
1
answer
45
views
How to reshape wide format data to long format? [duplicate]
I have a wide format dataset, which contains year variables (yr1, yr2, yr3), and duration variables (yr1_time, yr2_time, yr3_time). yr1 ranges from 2023 to 2025. yr2 and yr3 equals to yr1+1 or +2, ...
1
vote
1
answer
60
views
Using pivot_longer on two sets of columns
I've managed to achieve what I need, but the code is messy and I'm looking for a cleaner way to do it. I have two sets of columns that need pivoting in parallel.
data <- structure(list(well_short = ...
2
votes
2
answers
344
views
How to reshape (pivot_wider and pivot_longer) a pandas DataFame
I'm struggling in reshaping DataFrame (a little complicated) using pandas.
I have tried using pd.melt, .pivot(index=, columns=, values=), but it doesn't work perfectly as I intended.
as is :
date
...
0
votes
2
answers
89
views
How to pivot a column's values, making new, enumerated columns with pandas dataframe
I have a dataframe like:
id diag a_date
0 1 d1 55
1 1 d2 88
2 2 d5 22
3 2 d3 44
4 2 d4 88
5 2 d4 89
6 3 d1 11
7 3 d1 ...
1
vote
2
answers
168
views
Reshaping tables from long to wide format in R
set
inst
ind
color_Blue
1
0
0
70
1
0
1
60
1
0
2
50
1
1
0
30
1
1
1
20
1
1
2
66
2
0
0
35
2
0
1
22
2
0
2
28
2
1
0
90
2
1
1
47
2
1
2
23
I have data frame looks like this above and I want to ...
3
votes
2
answers
168
views
What is the equivalent of `unstack()` in data.table?
I want to convert the long to wide format of my data using data.table. Normally I use unstack(), but I don't know how to do it in data.table. Below is an example. As output I expect three columns and ...
2
votes
1
answer
50
views
transform data from wide to long in r [duplicate]
I have a dataset similar to this:
id_male<-rep(c(1:100),times=1)
df1<-data.frame(id_male)
df1$id_female <- sample(500:1000, length(df1$id_male), replace=TRUE)
df1$var_ma_1 <- sample(500:...