Copying column values up based on other column values - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Copying column values up based on other column values (/thread-31785.html) |
Copying column values up based on other column values - codelines - Jan-03-2021 Hello, I have this dataframe import numpy as np import pandas as pd from numpy.random import randn df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) is there a way to create a column S - which will copy column column Y values UP- if values in column Y are above 1 - otherwise return new value above zero?.I made this manually: thanks a lot!
RE: Copying column values up based on other column values - codelines - Jan-03-2021 thank you - I included all the code...the last column S was manually created by me as a reference for the code required for this operation...in excel there is a quick way to back-propagate a cell value by making it equal to the next one - eg A10=A11 - is there a quick way to do that in pandas given that it operates on arrays? |