简体   繁体   中英

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))

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM