'Extracting data from a column in a data frame in Python

I want to extract out the "A"(s) from this column. After doing that I want to be able to print the other data from other columns associated with "A" in the same row. However, my code printed this instead:

outputs:
UniqueCarrier       NaN
CancellationCode    NaN
Name: CancellationCode, dtype: object
None

The column CancellationCode looks like this:

  CancellationCode:
        NaN
         A
        NaN
         B
        NaN

I want to get it to print in a data frame format with the filtered rows and columns.

Here is my code below:

cancellation_reason = (flight_data_finalcopy["CancellationCode"] == "A")
cancellation_reasons_filtered = cancellation_reason[["UniqueCarrier", "AirlineID", "Origin"]]
print(display(cancellation_reasons_filtered))


Solution 1:[1]

try this

cancellation_reason=flight_data_finalcopy[flight_data_finalcopy["CancellationCode"] == "A"]
cancellation_reasons_filtered = cancellation_reason[["UniqueCarrier", "AirlineID", "Origin"]]
print(display(cancellation_reasons_filtered))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven G