第二讲code的问题

第二讲实例中的将'year', 'month', 'day'合并为‘date'的函数​
add_date_col_to_df(data_df)
我把它改为:
def add_date_col_to_df(data_df):
    '''
    data_df[['year', 'month', 'day']]=data_df[['year', 'month', 'day']].astype(str)
    print(type(data_df[['year', 'month', 'day']]))
    data_df['date']= data_df['year'].str.cat([data_df['month'], data_df['day']],sep='-')
    print(data_df)
    '''
    calendar = data_df[['year', 'month', 'day']].astype('str')
    print(type(calendar))
    data_df['date'] = calendar.year.str.cat([calendar.month], [calendar.day], sep='-')
    #print(data_df)
为什么提示错误:
Traceback (most recent call last):
  File "D:/PycharmProjects/lect02_proj_experiments/main.py", line 79, in <module>
    main()
  File "D:/PycharmProjects/lect02_proj_experiments/main.py", line 32, in main
    all_data_df = add_date_col_to_df(all_data_df)
  File "D:/PycharmProjects/lect02_proj_experiments/main.py", line 74, in add_date_col_to_df
    data_df['date'] = calendar.year.str.cat([calendar.month], [calendar.day], sep='-')
TypeError: cat() got multiple values for argument 'sep'

fish - Hadooper

赞同来自:

str.cat最多就接受两个参数。

要回复问题请先登录注册