Python Forum
New df from existing when condition occurs - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: New df from existing when condition occurs (/thread-15251.html)



New df from existing when condition occurs - Devilish - Jan-10-2019

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]