MYYA
您可以将zodiac_sign函数应用于数据框 -import pandas as pdfrom io import StringIO# Samplex = StringIO("""birthdate,answer,YEAR,MONTH-DAY1970-03-31,5,1970,03-311970-05-25,9,1970,05-251970-06-05,3,1970,06-051970-08-28,2,1970,08-28""")df = pd.read_csv(x, sep=',')df['birthdate'] = pd.to_datetime(df['birthdate'])df['zodiac_sign'] = df['birthdate'].apply(lambda x: zodiac_sign(x.day, x.strftime("%B").lower()))print(df)输出: birthdate answer YEAR MONTH-DAY zodiac_sign0 1970-03-31 5 1970 03-31 aries1 1970-05-25 9 1970 05-25 gemini2 1970-06-05 3 1970 06-05 Gemini3 1970-08-28 2 1970 08-28 virgo