Generation

generate functionThu, 09 Feb 2023

There is 'actors' Pandas dataframe: actorid name date_of_birth birth_city birth_country height_inches biography gender ethnicity networth 1002 1155 Jackie Chan 1954-04-07 Victoria Peak Hong Kong 68.0 Hong Kong's cheeky, lovable and best known fil... Male NaN 400000000.0 1387 69 Keanu Reeves 1964-09-02 Beirut Lebanon 73.0 Keanu Charles Reeves, whose first name means "... Male Lebanese 360000000.0 2252 141 Sean Connery 1930-08-25 Edinburgh UK 74.0 The tall, handsome and muscular Scottish actor... Male White 350000000.0 291 6 Bruce Willis 1955-03-19 Idar-Oberstein West Germany 72.0 Actor and musician Bruce Willis is well known ... Male White 250000000.0 Write a function that creates a dictionary with all the countries of North America, Western Europe. Then apply this function so that only the rows NOT corresponding to this dictionary are left in the dataframe.

def NAWE(country): NA = ['Canada', 'United States'] WE = ['United Kingdom', 'Germany', 'Netherlands'] if country in NA or country in WE: return False return True df = df[df['birth_country'].apply(NAWE)]

Questions about programming?Chat with your personal AI assistant