Python Forum

Full Version: New df from existing when condition occurs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have my DataFrame imported and converted. I have a column name 'Output' that contains 1s, zeros, and -1s as values...

I am wanting to crate a new DataFrame of all data and all columns WHEN 'Output' is 1... without changing the original DataFrame!!!

old DF example
0,0
1,1
2,0
3,1
new DF would be...
1,1
3,1
tried many combinations but haven't had success... As usual probably overcomplicating
if (RawData.Output() == 1):                               
    Data = RawData

I figured it out using...
Data = RawData[RawData.Output > 0]