Replicating value from one column into other columns based on row content

TomaszN

I have uploaded my dataset into Jupyter, it has 531 columns and 116 rows. So far I have replaced NaN values with 0 and now i am stucked with last step. I would like to replicate first columns values into other columns, based on condition that rows values will be bigger than 0.

I identified 3 parts to this task:

  1. iterate over whole set ( ex. list comprehension, for i in df)
  2. check whether values are bigger than 0 ( if i>0
  3. assign values from column0 to each field>0

enter image description here

I have tried list comprehension and googled how to duplicate values from Column0 based on the condition, but i am having difficulty understanding how can I replace them dynamically, ex. without fixed value. Additionally, i am wondering how should i define values to be inserted. How i started:

for i in df:
  if i>0:
    i...

I was considering using the where clause, but cannot get a hint how should i ask python to iterate over all table without defining which colums to replace specifically.

df = np.where(df == 0, df['replace all columns '], df[:1])

df[:,0] goes for replacing values with those from column0

Could you please suggest me any hints/ action points?

Pankaj Saini

Using a simple for loop. For example:

for col in df:
   df[col] = np.where(df[col]!=0, df['Column1'], df[col]) 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

unpivot columns, sum of value into one row group by other column based on start_month column that is bound to change

Pandas - Select row value from specific column based on value from other columns

SQL How to select columns multiple times on one row based on value in other column

Copy values from one column to other columns in same row based on specific criteria in Pandas

Pivoting row values in one column based on values in two other columns

Populate Pandas Dataframe column from other columns based on a condition and previous row value

How to select row value from given columns based on comparison of other column values in Pandas data frame?

Finding value from a third column based on specific row criteria of 2 other columns

For each row check if value in one column exists in two other columns

Having per group one value from column based on the comparision on other columns

How to filter for value in one column based on values from other columns in R?

R - assigning value to one column based on a comparison of two other columns

Update a Value in One Column Based on Criteria in Other Columns

How to remove duplicates in one column based on the value of other columns in psql

Pandas update one df from another based on other columns value

Select multiple columns from row based on MAX value of a column

Splitting value from one row to other rows in the same column in pandas

Copying data from one pandas dataframe to other based on column value

PostgreSQL : Display multiple columns from one column value based on conditions

pandas replicating and editing 'n' rows based on values from two other columns

How to convert rows that contain same value for one column but different for other columns into one single row using R?

pandas create new column based on values from other columns / apply a function of multiple columns, row-wise

pyspark - Dynamically select column content based on other column from the same row

Python: Assign missing value to rows in one column if any row is missing value in other columns

I want to attach one df column below another and assign row values based on other columns

Find the average value of a column based on date column and more than one other columns

In R, how to sum all other columns based on value of one column, without specifying column names?

Merge multiple columns into one by placing one below the other based on column value pandas dataframe

Create One Column from Six different Columns Where all the columns for a row contain a null value except for one