亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

需要在循環的幫助下對從 url 導入的多個 csv (1500 x 20) 文件的第一列執行列合并

需要在循環的幫助下對從 url 導入的多個 csv (1500 x 20) 文件的第一列執行列合并

UYOU 2023-03-16 09:55:36
對如何存儲、訪問和 mege dfs.c df 列具有相同的標題名稱感到困惑。代碼如下:for s in range(40):    # 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'      # problem area     c=f'uk{day_0}{month_0}{year_0}'     c  = pd.read_csv(a_0,engine='python')  # merge eod_a=c.merge(c,on='SYSTEM',how='left')
查看完整描述

1 回答

?
慕蓋茨4494581

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')


查看完整回答
反對 回復 2023-03-16
  • 1 回答
  • 0 關注
  • 89 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號