NameError while applying function

Viewed 19

I am trying to apply the function to a different column 'Year', but I seem to be missing something or my syntax is off because I keep getting a NameError thrown.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv('https://codefinity-content-media.s3.eu-west-1.amazonaws.com/46bdcecb-8503-44fc-bd22-3ece9d6e026e/third_df', index_col=0)

# Define function
def func(df, name):
# Create an empty list
list_df = [ ]
# Define the loop
  for i in df[name]:
    # Check if the length of the element is greater than 4
    if len(i) > 4:
       # If the condition is True append element
        list_df.append(i)
result = set(list_df)
# Return the obtained list
 return result

# Apply function to the column 'Year' and output the result
df['Year'].apply(list_df)
0 Answers
Related