Cnsolidating/Combining multiple excel files together with the help of Python & Pandas

Sdílet
Vložit
  • čas přidán 25. 07. 2024
  • Cnsolidating multiple excel files together with the help of python & pandas | Combine Excel Files with Python
    If you are wroking in Data Industry then certainly your day to day job involves dealing with many csv/excel files consolidation which makes the task really tedeous and make your work boaring, that's where we bring you this video which will help you do this task automatically.
    This video covers:
    00:00 - Introduction
    02:24 - Import libraries
    02:52 - Input and Output loaction assignment to python variables
    03:56 - Creating list of input files
    05:10 - Reading all the excel files one by one, consolidating them altogether and exporting it to excel automatically with the help of FOR LOOP
    Excel File - Excel_Files_to_Consolidate.zip
    URL - github.com/LEARNEREA/Python/t...
    Script - Consolidate Multiple Excel Files Into One.py
    URL - github.com/LEARNEREA/Python/t...
  • Věda a technologie

Komentáře • 75

  • @ajaykushwaha4233
    @ajaykushwaha4233 Před 2 lety +2

    The topic/problem description you choose are best.

  • @ajaykushwaha-je6mw
    @ajaykushwaha-je6mw Před 2 lety +1

    Excellent Sir, this is destination where I find answer of all my question.

  • @behappycool8576
    @behappycool8576 Před rokem +1

    Hi, Well Explained... Really really Appreciated. Thanks a lot. Good going.

  • @Helloworld-yf5fl
    @Helloworld-yf5fl Před rokem

    Excellent work. I have been just looking the solutions. You explained it very nicely. Thanks for vedio

  • @CleidsonMachadoDeveloper
    @CleidsonMachadoDeveloper Před 2 lety +1

    Thanks a lot!..,

  • @AldoAraA
    @AldoAraA Před rokem +1

    Helpfull! thanks a lot

  • @shubhambiyani8531
    @shubhambiyani8531 Před 2 lety

    Thanks!

  • @srichakrarajanilaya
    @srichakrarajanilaya Před rokem

    Sir. Brilliant video. But this video is for the files which has only one sheet in it. But my files have multiple sheets with them. How to consolidate based on those sheets

  • @estebanrojas1322
    @estebanrojas1322 Před 2 lety +1

    nice video ! , i am working on a script for some bank excel files. Is there any of your videos talking about appending an existing sheet?

    • @learnerea
      @learnerea  Před 2 lety

      You can import the existing excel in python/pandas then import other excels which you want to append, then do the appending in python itself and then export the final data to excel

  • @erniehsieh7430
    @erniehsieh7430 Před 2 lety +1

    Great video, when I used the code it gave me an error of list index out of range, any idea why that might happen ?

    • @learnerea
      @learnerea  Před 2 lety

      Understood,
      please put your code here, we will check and suggest you the solution

  • @arunm3397
    @arunm3397 Před 2 lety +1

    Hi,
    This is very helpful but i have a question what if my business need is to see only one file with all these excel but i dont want to append it rather i want electronics in separate sheet, Fashion in separate sheet of single workbook what logic can be use in that case
    Thanks

    • @learnerea
      @learnerea  Před 2 lety

      Hi Arun,
      here is the video for you -
      czcams.com/video/vyFbr90fMiM/video.html

  • @choomeiz6590
    @choomeiz6590 Před 2 lety +1

    Hi, is this the same method to combine if the files each have different headers?

    • @learnerea
      @learnerea  Před rokem

      that's little subjective depending on the purpose....
      if you just want to combine them one below another, for sure you can use this method... the only problem is, the file which doesn't have a particular column which is available in another one, in the final data you will get missing values in those columns against the rows coming from the file which doesn't have that column

  • @howard_roark1210
    @howard_roark1210 Před 2 lety +1

    hello thanks for explaining! This is throwing me the following error : "OptionError: "No such keys(s): 'io.excel.zip.reader'"
    could you please help me

    • @learnerea
      @learnerea  Před 2 lety

      Of you are using the line
      If file.endswith('xlsx')
      You mus not get this error
      However to be on safer side I recommend you remove the zipped file which you have in the folder which you are looking into for the Excel files

  • @kritikasomani_iift7602
    @kritikasomani_iift7602 Před 2 lety +1

    Hi how do I make a column in the consolidated file that states the original file name of the data

    • @learnerea
      @learnerea  Před 2 lety

      use the below line just after the line where it's reading the excel file in for loop in the video
      df['imported_file'] = file

  • @dhanuandey3667
    @dhanuandey3667 Před 2 lety +1

    what if each file has multiple sheets in it and we have to combine each sheet respectively.i.e, sheet1 in file 1 combined with sheet 1 in files and sheet 2 file1 with sheet2 in file2...

    • @learnerea
      @learnerea  Před 2 lety

      Hope you got its solution in the another video

  • @maracuyapassionfruit
    @maracuyapassionfruit Před 2 lety +1

    Mate, thank you very much. However, this will only work if the Excel files have only one sheet, right? What about if those Excel files have many sheets and I only want to append the sheets with a specific name?

    • @learnerea
      @learnerea  Před 2 lety

      Hi @Agustin Nosiglia,
      Bringing it, we will make a video for this as well soon.

    • @learnerea
      @learnerea  Před 2 lety

      Hi Agustin,
      If I understood the problem statement correctly then this is what you are looking for -
      czcams.com/video/r60J5YZKMLs/video.html

    • @pambharronak004
      @pambharronak004 Před 2 lety +2

      df = pd.read_excel(input_loc + files, sheet_name = ' your sheet name')

  • @anhnhatnguyet4628
    @anhnhatnguyet4628 Před rokem

    How to access Localhost like this video?

  • @musavirhussainburiro3579

    Iam finding dificulty in excuting the code please help me with this. error in the part below
    finalDF = pd.DataFrame()
    for files in filelist:
    if files.endswith(".xlsx"):
    df = pd.read_excel(input_loc+files)
    finalDf = finalDf.append(Df)

    finalDf.to_excel(output_loc+"finalDf.xlsx")
    "NameError: name 'finalDf' is not defined" please help

    • @learnerea
      @learnerea  Před rokem

      Look at the first statement where you are defining finalDF, it has capital letter "DF", while when you are using it it has small "f", either make it finalDf everywhere or make it finalDF everywhere..
      happy learning.

  • @SameerAli-nm8xn
    @SameerAli-nm8xn Před rokem +1

    Sir I am doing everything as shown in video but the values is not showing any n my newdf. How to resolve it please help

    • @learnerea
      @learnerea  Před rokem

      Put your script here once so that I could have a look and could support you

  • @pambharronak004
    @pambharronak004 Před 2 lety +1

    For a specific sheet
    df = pd.read_excel(input_loc + files, sheet_name = ' your sheet name')

    • @learnerea
      @learnerea  Před 2 lety

      this will work if the sheet name is same in all the excel files... if you need to have this one also dynamic, the below one can give some idea and basis on which it can be achieved -
      czcams.com/video/r60J5YZKMLs/video.html

  • @qianjunrui2338
    @qianjunrui2338 Před 2 lety

    Great video , when I try this , have value error : excel format cannot be determined, you must specify an engine manually. Any idea how to solve this ?

    • @learnerea
      @learnerea  Před 2 lety

      Put your code here, then only we will be to analyse and provide the solution

  • @yogeetagoyal2086
    @yogeetagoyal2086 Před rokem +1

    Sir I m beginner for python, how to work with this Jupyter. I need to install or something else..plz let me know

    • @learnerea
      @learnerea  Před rokem

      if you are still looking for an answer to this, refer to the below -
      czcams.com/video/rwHqzBiWPHQ/video.html
      it should help

  • @V.MITHUNCHANNEL
    @V.MITHUNCHANNEL Před rokem +1

    super,can please do some videos on merging multiple excel files with multiple sheets to one master excel files with sheets

  • @kunaltiwari3089
    @kunaltiwari3089 Před rokem

    Hi sir, is their anyway to combine multiple csv files into one excel workbook in multiple sheets?I want it in multiple sheets in one workbook not in single sheet.

    • @learnerea
      @learnerea  Před rokem

      first filter the data and then export that on the respective sheets in same excel file...
      let me know if need further help

  • @alikhanak123
    @alikhanak123 Před 2 lety

    How can i add file name from which the data is fetched in the concat file.

    • @learnerea
      @learnerea  Před 2 lety

      use the below line just after the line where it's reading the excel file in for loop in the video
      df['imported_file'] = file

  • @sulaimanshah5125
    @sulaimanshah5125 Před 2 lety +2

    Hi sir great video. But what if I want to add new data into the final output? How would I do that then?

    • @learnerea
      @learnerea  Před 2 lety

      Depending on what sort of or how you want add.. if you want to add another dataframes you can do so by using concatenation, append or merge whatever fits to the requirements - to learn this, you can start with this video and follow the series
      czcams.com/video/06iGLesHi8g/video.html
      If you just want to add a column to the final dataframe then simply you can -
      FinalDf['newColumn']=your_column

    • @antishwow
      @antishwow Před rokem

      @@learnerea Hi, my sincere apologies for replaying this late but I think the problem to be solved is still waiting for us.:) First through I want to thank you so much for your time and support on the matter! I will send you the sample data with the problem description and what I have done and what I want in the end. Thanks!

  • @hirengajjar4159
    @hirengajjar4159 Před 2 lety

    i want to marge multiple excel, all excel have common 3 sheets. please help to get code for the same, i want all data merge in new blank excel sheet wise

    • @learnerea
      @learnerea  Před 2 lety

      replied on the another comment, please try..
      will be happy to help further

  • @ivan7335
    @ivan7335 Před 9 měsíci

    Hi, i try to run ur code and it said "DataFrame' object has no attribute 'append'", i read some article and try to change it with concat and it still doesnt work. Is there any idea on this? Thanks in advance.

    • @learnerea
      @learnerea  Před 9 měsíci

      Can you please put your script here for us to analyse that

    • @ivan7335
      @ivan7335 Před 9 měsíci

      @@learnerea Nvm, Im fine, thank you very much for your code. Appreciate it m8

  • @rrrtttzzzrrr6649
    @rrrtttzzzrrr6649 Před 2 lety +1

    Can you do it in python script?

    • @learnerea
      @learnerea  Před 2 lety

      If you mean in native and not by using any library, in native python we don't have a dataframe what we have is dictionary, lists, tuples... if you want to merge dataframe then first you gotta convert them in any of the above and then possible it can be done

  • @antishwow
    @antishwow Před 2 lety

    Hi, that is a good tutorial. However, you have used a small number of excel files and have similar column names. The real challenge is what if you have different column names, or rather inconsistent column names and the number of files is say 300? That is what you get in real-world data?

    • @learnerea
      @learnerea  Před 2 lety +1

      Hi Anteneh,
      Thanks for watching the video and posting your issue.
      Doesn't seem to be a huge matter of concern. First of all you need to break down the problem in steps and then solve it -
      1. What is the end result that you nee
      2. What is the current input which you have
      lets start from point 2 -
      1. You might have different files with different number of collumns - that's fine when you combine them all together, there will be certain columns with missing values and that's a separate issue to figure out.
      2. You might have different files with different column names - Same as point number 1
      3. You might have different files with different column names but the content are same.. e.g. one file has the column name "Gender" while other one is "Sex"... this is also fine. my recommendation is to do the consolidation first then figure out all such columns and combine them all together...
      Not sure if this is going to help...
      if you want, you can share some let say 5-10 files over the mail id learnerea.edu@gmail.com.. and I'll try to provide you solution with the help of this sample

  • @hemalathakaramala2
    @hemalathakaramala2 Před 11 měsíci

    I have understood the code snippet for consolidating multiple input files in one new excel file. My question is if input files contain hidden records. those hidden records should not be visible on output file. How to do python code for this requirement. please share who knows

    • @learnerea
      @learnerea  Před 11 měsíci

      You must be having some criteria to hide the records..
      after consolidation of the data, use that criteria to filter them out..
      for filtering the dataframe you can check out these specific videos
      czcams.com/video/HqG7Gvq1dWI/video.htmlsi=a7nW_FPrHCBuu6wi
      czcams.com/video/FDlOyi9dFt8/video.htmlsi=4RD1bvTc8LszHH3O

  • @ajaykushwaha-je6mw
    @ajaykushwaha-je6mw Před 2 lety +1

    Sir I have one request, kindly create a video on OOP with real life situation like we create multiple file in pycharm, VS code etc. and call other other Class from one place like that video i am requesting.
    Like we have one main file app.py for EDA whave seperate file, data cleaning seperate file, Model building seperate file, how to connect all of them with app.py file.

  • @puransingh6999
    @puransingh6999 Před rokem

    SIR, HOW TO RUN 1 OR MORE EXCEL FILE, BY PYTHON CODE LIVR RUN, FROM LINK , ie. NSE, ETC

    • @learnerea
      @learnerea  Před rokem

      Can you give some examples to clarify on this doubt

  • @alikhanak123
    @alikhanak123 Před 2 lety

    Gives error "can only concatrbate Str (not list) to str

    • @learnerea
      @learnerea  Před 2 lety

      can you please put your complete script here along with the complete error message.. I'll try my best to solve this.

  • @abhinayyagnamurthy
    @abhinayyagnamurthy Před rokem

    I follow this code but in output my output file is blank

  • @yogeetagoyal2086
    @yogeetagoyal2086 Před rokem

    Sir I m following your script but showing error os error file name directory name or volume label syntaxes is incorrect. It is showing. How to resolve this?

    • @learnerea
      @learnerea  Před rokem +1

      Put your code here
      We will have a look

    • @yogeetagoyal2086
      @yogeetagoyal2086 Před rokem

      @@learnerea
      import pandas as pd
      import os
      input_loc = "D:\document\temp\output"
      output_loc = "D:\document\temp\output\temp_out"
      fileList = os.listdir(input_loc)
      This is my code and I have entered the input location where my excel files are present which need to be merged and the output location where i need merged files. it will be more convenient if you share any personal contact details to ask doubts over there. I will be highly thankful to you

    • @yogeetagoyal2086
      @yogeetagoyal2086 Před rokem

      Plz give me reply

    • @learnerea
      @learnerea  Před rokem

      The code looks okay, just ensure two things -
      1. the location exist in your system
      2. if you are working on windows, try changing the backward slashes (\) with forward slashes (/) in the location and always end it with a slash, e.g. instead of just
      "D:\document\temp\output"
      change it to
      "D:/document/temp/output/"

    • @yogeetagoyal2086
      @yogeetagoyal2086 Před rokem

      Plz provide your mail id,I will share my code pic over there. I m still getting error.