'Exception when using df.apply on empty dataframe

I have code that is similar to what I've provided below but the problem is it exceptions when the dataframe is empty.

raise ValueError("Columns must be same length as key")
ValueError: Columns must be same length as key
df['Started'] = df.apply(lambda x: 'yes' if x['current_page'] > 0 else 'no', axis = 1)

Is there a way to write this apply so that it doesn't exception out other than wrapping it in an if check?

if (not df.empty):
    df['Started'] = df.apply(lambda x: 'yes' if x['current_page'] > 0 else 'no', axis = 1)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source