1 回答

TA貢獻1850條經驗 獲得超11個贊
考慮構建一個數據框列表,然后調用concat
水平合并:
def get_data(s):
# a func which returns historical business dates
ago_Ybd_0 = (date_by_adding_business_days(datetime.date(2020, 7, 17), s, Holiday))
year_0, month_0, day_0 = ago_Ybd_0.strftime("%Y-%b-%d").split("-")
month_0 = month_0.upper()
#import / unzip/ read file
!wget
'https://www.ukp.com/content/historical/{year_0}/{month_0}/cm{day_0}
{month_0}{year_0}kp.csv.zip'
!unzip 'uk{day_0}{month_0}{year_0}kp.csv.zip'
a_0=f'uk{day_0}{month_0}{year_0}kp.csv.zip'
# RETURN DATA FRAME, SETTING SYSTEM AS INDEX
return pd.read_csv(a_0, engine='python', index_col='SYSTEM')
# BUILD LIST OF DFs VIA LIST COMPREHENSION
df_list = [get_data(s) for s in range(40)]
# BIND ALL DFs BY COLUMNS INTO SINGLE DF
final_df = pd.concat(df_list, axis='columns')
添加回答
舉報