Here is an example dataset that I have: I want to take all the values that have “1” in them in the Column “C2” and shift them to replace the adjacent values in column “C1”. So the output should look like: Alternatively, I could create a new column with these values replaced. Main point is, that I need all the
Tag: dataframe
How to create a list from dataframe pandas
My dataset contains columns of usersID and itemsID that they have purchased. Each user might have purchased more than 1 item. I neeed to make a list so that the key will be the userID and the values the itemsID he purchased for example if user_1 has purchased [item_20,item_25,item_32], my dataset contains 3 rows for this user as follows row_1=
Need help converting column timestamp data into 2 seperate columns (Date,Time)
Fairly new to programming and python in general. Learning as I go. Breaking thing, ALOT, but learning ALOT. What I want to do, which I have not been able to figure out is create a CSV with certain columns. Currently, one of the columns, after I organize the data, is a date-timestamp, which I need to be separated into 2
Pandas subtract each column in dataframe_a from all columns of dataframe_b and write result to third dataframe
I have dataframe_a and dataframe_b filled with an variable number of columns but the same number of rows. I need to subtract each column of dfb from all dfa columns and create a new dataframe containing the subtracted values. Right now I’m doing this manually: then I’m using the concat function to concatenate all the columns: This all seems horribly
Calculate z-score for multiple columns of dataset on groupby and transform to original shape in pandas without using loop
I have a data frame Need to calculate Z-score for columns “c1”, “c2”, “c3” using groupby on “id”, and transform it to the original form without using the loop. Expected output: How to do it? Answer Use GroupBy.transform with DataFrame.join:
Copy the last seen non empty value of a column based on a condition in most efficient way in Pandas/Python
I need to copy and paste the previous non-empty value of a column based on a condition. I need to do it in the most efficient way because the number of rows is a couple of millions. Using for loop will be computationally costly. So it will be highly appreciated if somebody can help me in this regard. Based on
ffill col[c] based on col[a]==Value
I have a dataframe [pixel, total_time], i want to: Make a new column “total_time_one”, which takes total_time of pixel 1 and projects it I have acheved the above dataframe with : Howver the code is quite long and repeats itself, is there a function better suited? or a better solution? Also i do not undestand why if i put: It
filter dates using pandas from dataframe
I have a column of dates. I need to filter out those dates that fall between today’s date and end of the current month. If the dates fall between these dates then the next column showns “Y” Date Column 01/02/2021 03/02/2021 31/03/2021 Y 01/03/2021 07/03/2021 Y 08/03/2021 Y Since today’s date is 07/03/2021 three dates fall between 07/03/2021 and 31/03/2021.
Restructure Pandas DataFrame
I have the following DataFrame: play_id position frame x y 1 A_1 1 0.1 0.1 1 A_2 1 0.1 0.1 1 B_1 1 0.1 0.1 1 A_1 2 0.1 0.1 1 A_2 2 0.1 0.1 1 B_1 2 0.1 0.1 2 A_1 1 0.1 0.1 2 B_1 1 0.1 0.1 2 B_2 1 0.1 0.1 2 A_1 2 0.1 0.1
Pandas fillna based on a condition
I’m still new to pandas, but I have a dataframe in the following format: and I’m trying to fill all NaN fields in the ‘d_header’ column using the following conditions: ‘d_header’ column should be set only for rows belonging to the same group the group should be determined by the ‘d_prefix’ column value of a row immediately after non-Nan ‘d_header’