2

I am analyzing some data. I got my for loop to print in array format but i wanted to print the results back in a data frame format as i am working with data frames.

import itertools 

for time, flight in itertools.izip(flight_data["AirTime"], flight_data["UniqueCarrier"]):
    if time > 300:
        print (time, flight)
Outputs:(340, AA)

However, I want the output to return back in a dataframe format. Please assist thanks

1 Answer 1

2

Use boolean indexing:

print (flight_data[flight_data.AirTime > 300])

Sample:

flight_data = pd.DataFrame({'AirTime':[340,200,110],
                            'UniqueCarrier':['AA','SS','DD']})

print (flight_data)
   AirTime UniqueCarrier
0      340            AA
1      200            SS
2      110            DD


print (flight_data[flight_data.AirTime > 300])
   AirTime UniqueCarrier
0      340            AA
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.