python利用pandas對多個資料夾裡的excel進行合併,切割
程式碼如下
import os import pandas as pd df = pd.DataFrame(columns=['流水號','事件名稱','本方戶名','對方戶名','流水時間','操作員','交易額','流水標誌','扇區號']) l = [] num = [] def search(path): parents = os.listdir(path) sum = 0 for parent in parents: # 返回指定路徑下所有檔案和資料夾的名字,並存放於一個列表中 child = os.path.join(path,parent) if os.path.isdir(child): # 將多個路徑組合後返回 search(child) elif os.path.isfile(child): # 如果是目錄,則繼續遍歷子目錄的檔案 if os.path.splitext(child)[1] == '.xls': # 分割檔名和副檔名,並且副檔名為'xls' d = pd.read_excel(child) for i in range(len(d)): num.append(os.path.split(child)[1][0:9]) l.append(d) #search(r'C:\\Users\aming\\Desktop\\大學生行為分析\\後勤資料\\學生資料_LHJ_YJ') search(r'C:\\Users\aming\\Desktop\\大學生行為分析\\後勤資料\\學生資料_LHJ_YJ\1250111\2012-8-1_2014-7-15') df = pd.concat(l) da = pd.Series(num) df['學號'] = da df = df.drop(columns=['流水號','扇區號','流水號','操作員','流水標誌'],axis=1) #刪除整列全為NAN的列 df.to_excel('rone.xlsx',index=False) # 儲存為result檔案
相關推薦
python利用pandas對多個資料夾裡的excel進行合併,切割
程式碼如下 import os import pandas as pd df = pd.DataFrame(columns=['流水號','事件名稱','本方戶名','對方戶名','流水時間','操作員','交易額','流水標誌','扇區號']) l = []
計算多個資料夾中,總檔案個數(python)
# -*- coding: utf-8 -*- # Time:2017.03.28 # Author:coplin # Function:Count the number of image file.
python實現將多個檔案分配到多個資料夾
import os import shutil #path of imgr path = 'D:\\BaiduNetdiskDownload\\newim\\' #path of folder folderPath = 'D:\\BaiduNetdiskDo
OS 建立多個資料夾
import requests import os import json url='https://pvp.qq.com/web201605/js/herolist.json' html=requests.get(url) html_json=html.json() B=list(map(lambd
python 兩個資料夾裡的檔名對比
比如需要一個xml對應一個jpg時,有時候會不小心少了其中一個檔案,這時可以用以下程式碼比較缺少的是哪個檔案: # -*- coding: utf-8 -*- import os path1 = r'../diff' def file_name(file_dir): jpg_list =
MapReduce設定輸出檔案到多個資料夾下
一:自定義OutputFormat類 MapReduce預設的OutPutFormat會將結果輸出檔案放置到一個我們指定的目錄下,但如果想把輸出檔案根據某個條件,把滿足不同條件的內容分別輸出到不同的目錄下,就需要自定義實現OutputFormat類,且重寫RecordWriter方法。 在驅
java 同時建立多個資料夾和檔案
public void demo1() { try { File dir = new File("d:\\abc\\bcd"); if (!dir.exists()) { dir.mkdirs(); } File file = new
Unity 利用 UnityAction 對多個按鈕新增監聽
當有許多個按鈕需要新增監聽的時候,我們可以先使用UnityAction把這些方法監聽起來,再分別傳給按鈕。 public UnityEngine.Events.UnityAction[] allEvents = new UnityEngine.Events.UnityAction
nginx 一個域名配置多個資料夾
server { listen 80; server_name mall.cn; #charset koi8-r; access_log logs/access.log main; client_max_body_
Python利用os.walk遍歷資料夾
os.walk這個某塊是遍歷一個目錄常用的模組,它返回一個包含3個元素的元祖:dirpath,dirnames,filenames.dirpath是以string字串形式返回該目錄下所有的絕對路徑;dirnames是以列表list形式返回每一個絕對路徑下的資
spark讀取多個資料夾(巢狀)下的多個檔案
在正常呼叫過程中,難免需要對多個資料夾下的多個檔案進行讀取,然而之前只是明確了Spark具備讀取多個檔案的能力。 針對多個資料夾下的多個檔案,以前的做法是先進行資料夾的遍歷,然後再進行各個資料夾目錄的讀取。 今天在做測試的時候,居然發現spark原生就支援這樣的能力。
Spark中載入本地(或者hdfs)檔案以及 spark使用SparkContext例項的textFile讀取多個資料夾(巢狀)下的多個數據檔案
Spark中載入本地(或者hdfs)檔案以及 spark使用SparkContext例項的textFile讀取多個資料夾(巢狀)下的多個數據檔案 在正常呼叫過程中,難免需要對多個資料夾下的多個檔案進行讀取,然而之前只是明確了spark具備讀取多個檔案的能力。針對多個資料夾下
dockerfile COPY如何同時拷貝多個資料夾
首先,拷貝一個資料夾到容器裡的命令是 COPY src WORKDIR/src 那麼,同時拷貝多個資料夾就是這樣? COPY src1 \ src2 \ WORKDIR/ 但是這麼操作過後,你會發現容器裡面WORKDIR目錄
Python_合併多個資料夾下的多個csv檔案
# -*- coding:utf8 -*- import os.path import os import csv import re path = "D:\Datebase\data1\DataChallengeOne" #i = 0 files = os.listdir(path) with open(
python中利用os模組列印任意資料夾裡面的檔名字,當前資料夾路徑,已經其的目錄名字
import os import numpy as np def file_name(file_dir): for root, dirs, files in os.walk(file_dir): #print(root) # 當前目錄路徑
利用C++獲取某一資料夾下的所有檔名,並獲取不帶字尾的檔名字
來源:https://www.cnblogs.com/fnlingnzb-learner/p/6424563.html 那麼到底如何查詢檔案呢?我們需要一個結構體和幾個大家可能不太熟悉的函式。這些函式和結構體在<io.h>的標頭檔案中, 結構體為struct _finddata_t
利用pandas將csv格式資料寫入到excel
一、安裝模組 pip install pandas pip install xlwt 二、程式碼示例 1、csv檔案內容展示 2、程式碼 #!/usr/bin/env python #-*- coding:utf-8 -*- import pandas as p
【shell】對指定資料夾中檔案進行過濾,並修改檔案內容的shell指令碼
編寫shell指令碼,對某個資料夾內搜尋指定檔案並對檔案內容進行更改: 在桌面建立shell_test資料夾 進入shell_test資料夾,建立5個測試檔案 在shell_test資料夾中再建立一個666資料夾,繼續再建立5個檔案,如圖: 分
python-進階教程-多個字典(對映)的合併
0.摘要 當我們處理多個字典(或稱為對映,因為字典是Python中唯一的對映結構),可以通過將多個字典合併為一個字典的方式實現批量處理。 1.ChainMap類 a = {'x': 1, 'z': 3 } b = {'y':
springboot中多個不同物件的屬性進行比較,將不同的值用使用陣列查詢出,並儲存在意向表中
多表維護 @MethodParameter(desc="orgTenantTypeQueryAll",input="user",postType={},postName="",queryString="",httpMethod="get",userParam="user