There is a Pandas dataframe: 35929 Passage de Venus (1874) 3.027778 1874 40331 Sallie Gardner at a Gallop (1878) 2.909091 1878 4195 Athlete Swinging a Pick (1880) 2.666667 1880 8085 Buffalo Running (1883) 2.636364 1883 29860 Man Walking Around a Corner (1887) 1.750000 1887 53932 Traffic Crossing Leeds Bridge (1888) 2.375000 1888 36445 Pferd und Reiter Springen Über ein Hindernis (... 2.583333 1888 1778 Accordion Player (1888) 1.928571 1888 39900 Roundhay Garden Scene (1888) 2.605263 1888 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
def assignDecade(x): if type(x) is str: return np.nan else: return (str(int(x[:3]))+"0-") + (str(int(x[:3])+1)+"0") df['Decade of Release'] = df['Year'].map(assignDecade) df