i have data like this, data orders
I have to select any sub-category that has a negative profit
the data has 9000 rows
CodePudding user response:
Something like df.loc[df["Profits"] < 0]
should work.
CodePudding user response:
If I understand your question correctly, you want to select all the rows from your dataframe where the value in column Profit is negative (<0)
Assuming you are using a pandas dataframe named df. The following code should gives you all the Sub-Category where at least one row within the Sub-Category had negative profit.
df[(df.Profits < 0)]['Sub-Category'].unique()
You may want to first import your data to pandas. Assuming your data is stored in 'path/to/data/data.csv'
import pd
df = pd.read_csv('path/to/data/data.csv')