3,896 questions
3
votes
3
answers
179
views
How to reshape from long to wide format filling NAs with zeros
I have a long format table which already has NAs:
df <- data.frame(
ID = c(1, 1, 2, 2, 3),
region = c("A", "B", "A", "B", "A"),
status = c(1, ...
-1
votes
1
answer
207
views
Python Multiplication of Two Arrays that May or May Not Have Same Shape [closed]
I have a problem where I have two arrays that can possibly have different shapes that I want to multiply together. Let's say I have two cases (I'm just using zeros right now cause all I care about is ...
2
votes
2
answers
100
views
Multiindexed Pandas Series to Yes/No table [duplicate]
I have a MultiIndex table as follows
Index0 Index1 Variable
A 0 "a"
A 1 "x"
A 2 "t"
B 0 "x"
B 1 ...
1
vote
2
answers
132
views
What is the significance of shape[0] in reshaping images in the following code: train_images.reshape(train_images.shape[0], 28, 28,1)?
I need to reshape the mnist data to include a "1" for grayscale and the code below does this I believe. The original mnist data is in this shape: (60000, 28, 28). What is the significance of ...
2
votes
4
answers
148
views
How can I rotate two columns (that possess location and time) while keeping the first column (which contains names) as is?
I have a set of data that I am attempting to manipulate to generate occurrence data that has associated time bins and latitude bins.
My data consists of 19 latitudinal bins in intervals of 10 from -90 ...
1
vote
2
answers
91
views
Explode Function and Reshaping in one Step
I have:
keys = ["panda1", "panda2", "panda3"]
values = [["eats", "shoots"], ["shoots", "leaves"], ["eats", "leaves&...
2
votes
3
answers
63
views
R function to mutate 2 ID columns into two different rows/entries
I have a data frame of events that have two columns for attendance IDs
It looks like this.
event<-c(1:20)
name1<-c(101:120)
name2<-c(rep(NA,15),201:205)
df<-data.frame(event,name1,name2)
...
0
votes
3
answers
148
views
Pandas dataframe reshape with columns name [closed]
I have a dataframe like this:
>>> df
TYPE A B C D
0 IN 550 350 600 360
1 OUT 340 270 420 190
I want reshape it to this shape:
AIN AOUT BIN BOUT CIN COUT ...
0
votes
2
answers
223
views
R reshaping the data
data <- data.frame(
T2_husband = rnorm(5),
T2_wife = rnorm(5),
T1_husband = rnorm(5),
T1_wife = rnorm(5),
Dyad_ID = 1:5
)
I have 5 columns in the dataset. However, I want to make dataset ...
0
votes
0
answers
29
views
Trying to reshape a a data frame into long form [duplicate]
I have a dataset with 4 columns, a product description and 3 years (1996, 2007, 2020).
I want to change the table into the long format making so that it has 3 columns: Product, Year and the value that ...
2
votes
1
answer
56
views
Spell Data to Long in R
I have spell data that includes an ID, a group indicator and the length of the spell.
> d <- data.frame(ID = 1:10,
+ group = sample(c("a", "b"), 10, replace = T), ...
2
votes
1
answer
108
views
How to reshape a dataframe into wide format with specified column pairs [closed]
I have the following melted sample dataframe:
df_melted <- data.frame(ID = c(21, 21, 21, 21, 49, 49, 49, 49), instance = c(1, 1, 1, 1, 1, 1, 2, 2), variable = c("causeofdeath", "...
5
votes
3
answers
401
views
How can I consolidate all rows with the same ID in Polars?
I have a Polars dataframe with a lot of duplicate data I would like to consolidate.
Input:
shape: (3, 2)
┌─────┬──────┐
│ id ┆ data │
│ --- ┆ --- │
│ i64 ┆ str │
╞═════╪══════╡
│ 1 ┆ a │
│ 1 ...
0
votes
0
answers
96
views
InvalidArgumentError: Input to reshape is a tensor with X values, but the requested shape has Y [Op:Reshape] in Keras/TensorFlow
I am trying to implement a neural network using Keras and TensorFlow, and I encountered the following error:
InvalidArgumentError: Input to reshape is a tensor with 64 values, but the requested shape ...
0
votes
0
answers
106
views
Fixing the train-test resolution discrepancy in a YOLO model
I have trained a yolov8 model in order to detect handwritten digits on paper with MNIST dataset. The problem is that the images on the dataset are 416x416 and once the model is trained it gets really ...