calculated-columns

Defining a new column based on non null values in other columns

Defining a new column based on non null values in other columns Question: I working with two tables that I performed an outer join on. Below is the table. I want to create a column called Job Number which looks at the Job Number Salesforce and Job Number Coins columns and returns which ever one …

Total answers: 1

Pandas different mathematical operation, conditional on column value

Pandas different mathematical operation, conditional on column value Question: data= {‘start_value’:[10,20,30,40,50,60,70], ‘identifier’:[‘+’,’+’,’-‘,’-‘,’+’,’-‘,’-‘]} df = pd.DataFrame(data) start_value identifier 0 10 + 1 20 + 2 30 – 3 40 – 4 50 + 5 60 – 6 70 – I am attempting to created a new column "end_value" that results in either +5 or -5 to …

Total answers: 2

Creating custom names for columns based on other column names in pandas dataframe

Creating custom names for columns based on other column names in pandas dataframe Question: I have a dataframe like below: I am looking to create a column using difference or use any other calculations among columns. However, I looking to name the column so that it relfects the operation done. For ex below I am …

Total answers: 3

Pandas comparing values following each other

Pandas comparing values following each other Question: So the problem is to check are these values inside the same column are equal to each other i.e. df = pd.DataFrame(np.array([[1, 2, 3], [1, 5, 6], [7, 8, 9]]), columns=[‘a’, ‘b’, ‘c’]) And if the following values of ‘a’ column are equal is there any chance to …

Total answers: 1

Problem with Cumsum Single Column Groupby

Problem with Cumsum Single Column Groupby Question: my mind is blown so hoping you can help here:) I have data that I need to ‘cumsum’ by month and year and cannot figure out how to do it. My data looks like this – testdf: month year power_kwh 0 1 1990 416491241.4 1 2 1990 343033068.2 …

Total answers: 1

Categorizing a pandas column by another column

Categorizing a pandas column by another column Question: My data looks like this: I’m using the following script to populate the RP8_Recruise as either "Y" (NEAR_DIST< 100 meters) or "N" (NEAR_DIST> 100 meters). nrows = plots_dist_joined.shape[0] for i in range(0, nrows): # for plots that are within wanted distance from disturbance harvest if (plots_dist_joined.iloc[i,9] < …

Total answers: 1

Any simpler way to assign multiple columns in Python like R data.table :=

Any simpler way to assign multiple columns in Python like R data.table := Question: I’m wondering if there’s any simpler way to assign multiple columns in Python, just like the := in R data.table. For example, in Python I would have to write like this: df[‘Col_A’] = df.A/df.B df[‘Col_B’] = df.C/df.D df[‘Col_C’] = df.E/df.F * …

Total answers: 3