Python Forum
New df from existing when condition occurs
Thread Rating:
  • 3 Vote(s) - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New df from existing when condition occurs
#1
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  OSError occurs in Linux. anna17 2 185 Mar-23-2024, 10:00 PM
Last Post: snippsat
  else condition not called when if condition is false Sandz1286 10 5,736 Jun-05-2020, 05:01 PM
Last Post: ebolisa
  [HELP] Nested conditional? double condition followed by another condition. penahuse 25 7,698 Jun-01-2020, 06:00 PM
Last Post: penahuse
  how do i loop a "def ..." when error occurs? Stan2292 0 1,581 Aug-12-2019, 05:28 AM
Last Post: Stan2292
  How to make Python stops for debugging when the error occurs? Tim 5 5,771 Feb-16-2018, 09:50 AM
Last Post: Tim
  script closed before i can see the error that occurs? wrestlemy69 9 9,144 Dec-02-2016, 01:40 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020