简体   繁体   English

从 Python 中的数据框中的列中提取数据

[英]Extracting data from a column in a data frame in Python

I want to extract out the "A"(s) from this column.我想从此列中提取出“A”。 After doing that I want to be able to print the other data from other columns associated with "A" in the same row.这样做之后,我希望能够从同一行中与“A”关联的其他列打印其他数据。 However, my code printed this instead:但是,我的代码打印了这个:

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

The column CancellationCode looks like this: CancellationCode列如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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