简体   繁体   中英

Unable to subset the data from Pandas dataframe

I tried to create a subset from Pandas dataframe based on some conditions. I was able to create two subsets, but get a syntax error when trying to create another subset.

The dataframe is.csv file with column headings: Number, Environment, Phase, Type, Planned end date, Closure code, Closure Subcategory, Incident Caused by Change, Pending Change. What code should I try to create a subset using "Planned end date" wherein the records which have Planned end date more than 4 days from today's date should be in a different subset? I'd like to create a different subset with all "Successful" and "FULLY SUCCESSFUL" records, and also a different subset with has null values for Incident Caused by Change and Pending Change.

Original dataframe:

原始数据框

Subset error:

子集错误

No subset error:

没有子集错误

When you use the format df2.Closure Subcategory ==... , python uses only Closure as the column name, and assumes that everything after the space is another part of the statement. So when it sees the word "Subcategory" on its own after a dataframe column, it throws an error.

As @Alexander Cecile mentioned in the comment section, use the other method to call a column, eg df2['Closure Subcategory'] ==... , and the subset would be created.

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