I want to know how do i pass a variable as a argument in a function
df[col_name] not in range(18,121)
was wrong, as @Panagiotis Kanavos pointed out. A simpler method if you're not df['single'].between 18 and 120.all():`
In addition, if df['single'].isnull()
: was the wrong value. .any()
can be utilized.
Snippet:
df, meta = pyreadstat.read_sav("SL_2025.sav")
def single_check(single):
if df['single'].isnull().any():
print("Missing values")
if not df['single'].between(18, 120).all():
print("Range error")
else:
print("Data is correct")
You can pass a variable as a argument in a function.
single_check(df['hCurrAge'])