Skip to content
Advertisement

Add column to existing panas dataframe with values as ‘Top’ and ‘Bottom’

I want to create a column in the existing dataframe with values as ‘Top’ and Bottom’, catch is, size of the dataframe changes according to calculations.

For example:

JavaScript

I will always have even number of rows.

Please suggest a solution, thanks!

Advertisement

Answer

I don’t know exactly how your data is, but you can try something like this:

Hypothetical data:

JavaScript

Creating the new column

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement