0

I've converted an excel sheet into a dataframe, one of the columns states the rise and drop of prices from day 1 to month 2 as a percentage. For example there'll be '-15.4' or a positive percentage like '6.32' (%).

What i want to do is to only include the rows that have a positive value in that column.

This is my import:

 import pandas as pd

 ipo_data = pd.read_excel(r'C:\Users\ --- \OneDrive --- \ --- \IPO data.xlsx')
prp
  • 914
  • 1
  • 9
  • 24
dom_2108
  • 37
  • 5

2 Answers2

0

you want to slice the df like this:

only_positive_pct_df = ipo_data[ipo_data['pct_column'] > 0]
prp
  • 914
  • 1
  • 9
  • 24
0

The easiest way to do this is to just remove the values which are above 0 for the column you want to filter on.

ipo_data = ipo_data.loc[ipo_data[column_to_filter] > 0, :]

.loc expects the rows and column informations. As row information you provide

ipo_data[column_to_filter] > 0 which says you only want positive values while : refers to all columns, as you don't want to filter them.

Also, check this link for more information about slicing dataframes.

Márcio Coelho
  • 333
  • 3
  • 11