表白:黑白圣堂血天使,天劍鬼刀阿修羅。 講解對(duì)象:/pandas 怎么自由移動(dòng)每列數(shù)據(jù) 作者:融水公子 rsgz ===
今天這篇文章講解的就是使用pandas模塊,將order_20230705113030875.xlsx表格中訂單子表里面的每一列數(shù)據(jù)自由移動(dòng),如果全是文本數(shù)據(jù)的情況下 想實(shí)現(xiàn)這個(gè)需求那么pandas模塊能很快地處理import pandas as pd
# 定義表格路徑
file_path = r"C:\Users\Administrator\Desktop\order_20230705113030875.xlsx"
# 讀取原始表格數(shù)據(jù)
df_original = pd.read_excel(file_path, sheet_name="order_", engine='openpyxl', index_col=False)
# 創(chuàng)建新的子表單
df_order = pd.DataFrame(columns=['新列', '大圖(只顯示一張)', '運(yùn)單號(hào)', '尺寸', '產(chǎn)品數(shù)量', '顏色', 'sku編碼', 'temp'])
# 復(fù)制數(shù)據(jù)到訂單子表
df_order['新列'] = "" # 在這里插入空列
df_order['大圖(只顯示一張)'] = df_original.iloc[:, 5] # 第六列圖片復(fù)制到第二列
df_order['運(yùn)單號(hào)'] = df_original.iloc[:, 0] # 第一列運(yùn)單號(hào)復(fù)制到第三列
df_order['尺寸'] = df_original.iloc[:, 1] # 第二列產(chǎn)品規(guī)格復(fù)制到第四列,提取Size后面的字符串
df_order['產(chǎn)品數(shù)量'] = df_original.iloc[:, 2] # 第三列產(chǎn)品數(shù)量復(fù)制到第五列
df_order['顏色'] = df_original.iloc[:, 1] # 第二列產(chǎn)品規(guī)格復(fù)制到第六列,提取Color和Size之間的字符串
df_order['sku編碼'] = df_original.iloc[:, 4] # 第五列SKU復(fù)制到第七列
df_order['temp'] = df_original.iloc[:, 5] # 第六列圖片復(fù)制到第八列
# 將訂單子表寫入新的Excel文件中的子表
with pd.ExcelWriter(file_path, mode='a', engine='openpyxl') as writer:
df_order.to_excel(writer, sheet_name='訂單', index=False) 上面的結(jié)果可以很快的移動(dòng)表格種的每一列數(shù)據(jù) 非常的方便 === 公眾號(hào):不浪仙人 謝謝大家的支持!可以點(diǎn)擊我的頭像,進(jìn)入我的空間瀏覽更多文章呢。建議大家360doc[www.hbhlny.cn]注冊(cè)一個(gè)賬號(hào)登錄,里面真的有很多優(yōu)秀的文章,歡迎大家的到來。 --- ';
|