Skip to content

Tag: pandas

Pandas union with parent ids in the same dataframe

I have a pandas dataframe that looks like this: I want to return the folder structure for each line in a separate colunm, for example line 1: A is the root there is no parent all ids are 0 = A line 2: B is under A, id = 1, so the path is A/B line 3: C is under

Python dataframe vectorizing for loop

I would like to vectorize this piece of python code with for loop conditioned on current state for speed and efficiency. values for df_B are computed based on current-state (state) AND corresponding df_A value. Any ideas would be appreciated. Answer This seems overkill. Your state variable basically is the pr…

pandas countif negative using where()

Below is the code and output, what I’m trying to get is shown in the “exp” column, as you can see the “countif” column just counts 5 columns, but I want it to only count negative values. So for example: index 0, df1[0] should equal 2 What am I doing wrong? Python Output Answer Fi…