I’m a beginner in python.
I need to find out what function should I use in order to create a new dataset (df2) for empty original dataset (df). For example,
df2 = df['count_days'].dt.days >= 1
When I don’t have no days to count in the dataset (empty data), I get an error.
Can I use if else statement to resolve this issue?
For example:
if df['count_days'].dt.days >= 1
df2
else
print("No Data")
BTW – I sometimes would have empty dataset because there is no record available.
Thank you!
>Solution :
Yes you can use the if and else statements:
import pandas as pd
if df.empty:
print("No Data")
else:
df2 = df['count_days'].dt.days >= 1