Generation

generate functionWed, 18 Jan 2023

There is a Pandas dataframe: id title rating decade 4728 Bad Education (2019) 0.5 2010-2020 35638 35638 Palooka (1934) 0.5 1934 1930-1940 21445 21445 High Moon (2019) 0.5 2019 2010-2020 40291 40291 Saint Maud (2019) 0.5 2019 2010-2020 29462 29462 Mad at the Moon (1992) 0.5 1992 1990-2000 46978 46978 The Butterfly Ball (1977) 0.5 1977 1970-1980 42931 42931 Snowboarďáci (2004) 0.5 2004 2000-2010 38670 38670 Recon 2020: The Caprini Massacre (2004) 0.5 2004 2000-2010 25506 25506 Karagoez catalogo 9,5 (1983) 0.5 1983 1980-1990 43989 43989 Starting a Skyscraper (1902) 0.5 1902 1900-1910 Write a function that shows which decade had the most movies with a high rating Write a function that creates a "Decade of Release" column and assigns a decade to each movie based on the values in the "Year" column Example: 1889 Result: 1880-1890 Example 2: 1954 Result 2: 1950-1960 Example 3: 2011 Result 3: 2010-2020 Example 4: raovyavas Result: NaN

import pandas as pd def decade(year): if year < 1910: return str(year - year%10) + '-' + str(year - year%10 + 10) elif year > 2009: return str(year - year%10) + '-' + str(year - year%10 + 10) else: return str(year - year%10) + '-' + str(year - year%10 + 9) df['Decade of Release'] = df['Year'].map(decade)

Questions about programming?Chat with your personal AI assistant