我正在尝试删除数据集的特定行,但总是出现相同的错误。我有几个候选人,我只想和两个人一起工作。我试着用“不在”的状态,但当我需要可视化它时,使用了所有的候选者。我使用相同的公式来删除列,并且它起作用了!有什么想法吗?谢谢
poll = poll.drop(["Alexandria Ocasio-Cortez","Amy Klobuchar","Andrew Yang","Barack Obama","Bernard Sanders","Beto O'Rourke","Bill de Blasio","Charles E. Schumer","Elizabeth Warren","Cory A. Booker","Eric Swalwell","Howard Schultz","Hillary Rodham Clinton","John K. Delaney","Jay Robert Inslee","John Hickenlooper","Kamala D. Harris","Julián Castro","Justin Amash","Marianne Williamson","Kirsten E. Gillibrand","Megan Rapinoe","Michelle Obama","Michael F. Bennet","Michael Bloomberg","Mike Pence","Mike Gravel","Nancy Pelosi","Pete Buttigieg","Oprah Winfrey","Nimrata R. Haley","Sherrod Brown","Seth Moulton","Steve Bullock","Tulsi Gabbard","Tom Steyer","Tulsi Gabbard","Wayne Messam"])我也试着在最后添加了axis=1。
数据集:https://projects.fivethirtyeight.com/polls-page/president_polls.csv
发布于 2020-06-11 00:31:26
假设这是你的名单,
namelist = ["Alexandria Ocasio-Cortez","Amy Klobuchar","Andrew Yang","Barack Obama","Bernard Sanders","Beto O'Rourke","Bill de Blasio","Charles E. Schumer","Elizabeth Warren","Cory A. Booker","Eric Swalwell","Howard Schultz","Hillary Rodham Clinton","John K. Delaney","Jay Robert Inslee","John Hickenlooper","Kamala D. Harris","Julián Castro","Justin Amash","Marianne Williamson","Kirsten E. Gillibrand","Megan Rapinoe","Michelle Obama","Michael F. Bennet","Michael Bloomberg","Mike Pence","Mike Gravel","Nancy Pelosi","Pete Buttigieg","Oprah Winfrey","Nimrata R. Haley","Sherrod Brown","Seth Moulton","Steve Bullock","Tulsi Gabbard","Tom Steyer","Tulsi Gabbard","Wayne Messam"]poll是您的数据帧,包含这些名称的列称为Candidates
使用以下命令:
poll = poll[~poll['Candidates'].isin(namelist)]
https://stackoverflow.com/questions/62308016
复制相似问题