第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

重復(fù)計算的最佳實踐

重復(fù)計算的最佳實踐

largeQ 2023-06-20 16:27:19
機器中的齒輪:數(shù)據(jù)包含當前 12 個月的數(shù)據(jù)并水平堆疊。每個月都會修改更新并附加新的月份。  ID  |Date        |Month1_a |Month1_b |Month1_c |Month2_a |Month2_b |Month2_c |Month3_a |Month3_b |Month3_c  ##  |MM/DD/YYYY  |abc      |zxy      |123      |NULL     |zxy      |122      |abc      |zxy      |123實際數(shù)據(jù)文件沒有標題,并作為每月第 1 個月的不同文件等在下游攝取。ID  | Date       |Month1_a |Month1_b |Month1_c |New Column##  |MM/DD/YYYY  |abc      |zxy      |123      | #ID  | Date       |Month2_a  |Month2_b |Month2_c |New Column##  |MM/DD/YYYY  |NULL      |zxy      |122      | #除了復(fù)制文件 12 次。是否有任何關(guān)于閱讀一次并循環(huán)創(chuàng)建我的輸出的建議。我已經(jīng)制定了第 1 個月的邏輯,我對如何進入第 2 個月以上感到困惑。最初是想讀取文件 > 刪除 Month 3+ > Drop Month 1 > Run Logic,但我不確定是否有更好/最佳實踐。謝謝。
查看完整描述

1 回答

?
寶慕林4294392

TA貢獻2021條經(jīng)驗 獲得超8個贊

這將輸出 n 個 csv 文件,其中 n 是輸入數(shù)據(jù)中的月數(shù)。希望這就是您所追求的。


import pandas as pd


df = pd.read_csv('my_data.csv', sep='|')


# Strip whitespace from column names

df.columns = [x.strip() for x in df.columns]


# Get a set of months in the data by splitting on _ and removing 'Month' from

# the first part

months = set([x.split('_')[0].replace('Month','') for x in df.columns if 'Month' in x])


# For each numeric month in months, add those columns with that number in it to

# the ID and Date columns and write to a csv with that month number in the csv title

for month in months:

    base_columns = ['ID','Date']

    base_columns.extend([x for x in df.columns if 'Month'+month in x])

    df[base_columns].to_csv(f'Month_{month}.csv', index=False)


查看完整回答
反對 回復(fù) 2023-06-20
  • 1 回答
  • 0 關(guān)注
  • 159 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號