Combine CSV files using Python

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • Manually combining CSV files into one master is time consuming, and labor intensive, and especially if you have a large number of CSV files. So why not write a Python program to automate the task? And the best part is it will take less than 5 minutes to write the code.
    In this tutorial, we will learn how to create a Python program to automate CSV files merging.
    Buy Me a Coffee? Your support is much appreciated!
    ----------------------------------------------------------------------------------------------------------------
    PayPal Me: www.paypal.me/...
    Venmo: @Jie-Jenn
    Support my channel so I can continue making free contents
    ---------------------------------------------------------------------------------------------------------------
    Patreon: / jiejenn
    By shopping on Amazon → amzn.to/2JkGeMD
    More tutorial videos on my website → LearnDataAnaly...
    Follow Me on Facebook → / learn-data-analysis-10...
    Business Inquiring: UA-cam@LearnDataAnalysis.org
    Tag:
    #PandasTutorial #DataAnalysis or

КОМЕНТАРІ • 66

  • @chetansonar9320
    @chetansonar9320 3 роки тому +3

    You have no idea how much this videos has helped me... Amazing! I am gonna hit subscribe and press the bell icon to that... Cheers!

  • @BiswarupMandal
    @BiswarupMandal Рік тому

    This is really helpful. What I liked about this code is that it is very short and simple.

  • @paranoya733
    @paranoya733 Рік тому

    After bullshiting my job interview, i found this video.. thank u

  • @nurulfadillah1248
    @nurulfadillah1248 Рік тому

    very useful. this is the only tutorial that gets me the right result. thank you very much

  • @amirtahaehsaei1609
    @amirtahaehsaei1609 3 роки тому +2

    it hit right at the spot, many thanks

  • @austinhomolka
    @austinhomolka 3 роки тому +2

    What a great video. Thank you for making it. It's amazing how powerful of a tool you can create from just a few lines of code. Thanks for the tutorial Jie!

  • @mariannygodoymacias2957
    @mariannygodoymacias2957 3 роки тому +2

    just what I needed, thank you so much :D

  • @zhichaozhang1580
    @zhichaozhang1580 3 роки тому +1

    thanks for your courses

  • @tatendagutuza3866
    @tatendagutuza3866 Рік тому +1

    Good stuff. How do I adjust the code when the csv files are located in a different location with the python file?

  • @asimjavaid5836
    @asimjavaid5836 Рік тому

    Your Subscription and hit like is really due on every learner.... Great teaches

  • @KhalilYasser
    @KhalilYasser 3 роки тому

    Awesome as usual Jie Jenn.

  • @Krauzerin11
    @Krauzerin11 6 місяців тому +1

    Great video, just real confusing your miss pronunciation of the word "object", it sounds like Agile, which gets you confused

  • @pankajgoikar4158
    @pankajgoikar4158 2 роки тому

    Thank you. Saved my time.

  • @pankajgoikar4158
    @pankajgoikar4158 Рік тому

    Thank you again.

  • @user-fw3vv4id5z
    @user-fw3vv4id5z Рік тому

    Thank you, very helpful!!

  • @rajvardhansinghpanwar3921
    @rajvardhansinghpanwar3921 6 місяців тому

    Mine is showing dataframe has no attribute 'append'

  • @saimali_2001
    @saimali_2001 3 роки тому

    thanks a lot for making this!

  • @michael3226
    @michael3226 2 роки тому

    I have an error or NO COLUMN TO PARSE FROM FILE. How can I handle this?

  • @johnpineda7692
    @johnpineda7692 Рік тому

    Thanks Bro!

  • @swarnavdeb2064
    @swarnavdeb2064 2 роки тому +1

    you didnt mentioned the specified path

    • @jiejenn
      @jiejenn  2 роки тому

      Not sure if I understand your question.

    • @swarnavdeb2064
      @swarnavdeb2064 2 роки тому

      @@jiejenn What I meant was inorder to read a file a specific file path is required, but in this case the file path is not given so where exactly is the data being retrieved from?

    • @jiejenn
      @jiejenn  2 роки тому

      Please Google os.getcwd().

  • @tokelo2547
    @tokelo2547 Рік тому

    Mine is not saving the combined files but the script is not returning an error

  • @sportsmania2841
    @sportsmania2841 2 роки тому +1

    Hi , I have two row headers so it skips one row but second row keeps on repeating. I dont want the headers to repeat only data to be concatenate under the first file header lines. can you help?

    • @JAZZMAINAWABBS
      @JAZZMAINAWABBS 2 роки тому

      did you get your answer ? am also stuck

    • @sportsmania2841
      @sportsmania2841 2 роки тому

      @@JAZZMAINAWABBS not yet, still waiting.....😐

  • @brunodobelinguimaraes4900
    @brunodobelinguimaraes4900 3 роки тому

    really good video my friend

  • @drujene
    @drujene 2 роки тому +1

    this helps a lot, and i have a question. what if there is non english in that csv files, how do you construct it to english?

    • @jiejenn
      @jiejenn  2 роки тому

      You probably need to translate the content first.

  • @lovrosibenik1070
    @lovrosibenik1070 Рік тому

    How do I specify the folder from where I want to merge my files

  • @Dennis_Smits
    @Dennis_Smits 2 роки тому +1

    line 7
    if file.endswith('.csv')
    ^
    SyntaxError: expected ':'
    Process finished with exit code 1
    This is de error code i get, is the any one who can help

    • @jiejenn
      @jiejenn  2 роки тому +1

      You are missing a colon at the end.

  • @toxiclife
    @toxiclife 2 роки тому

    Hey, great video, please do tell, if I want to merge all CSV files into one workbook but with different sheets only, like the combined workbook will have 3 sheets separately only. How to do that.

  • @azizt6773
    @azizt6773 6 місяців тому

    i believe there are been a change to the script for the DataFrame
    for this line master_df = master_df.append(pd.read_csv(file))
    ^^^^^^^^^^^^^^^^^^^
    the word append doesn't get recognized since the system throws an exception that says
    AttributeError: 'DataFrame' object has no attribute 'append'. Did you mean: '_append'?
    EDIT!!: on the line i have mentioned u need to add ._append instead of .append only just like this
    master_df = master_df._append(pd.read_csv(file))
    just copy what i did then change the variable name to your desire

    • @jiejenn
      @jiejenn  6 місяців тому

      I just tried, it is working for me. But if that still doesn't work for you, try master_df = pd.concat([master_df, pd.read_csv(file)], ignore_index=True)

  • @Mia-td3bx
    @Mia-td3bx 2 роки тому

    love it!!!

  • @mitragupta7548
    @mitragupta7548 3 роки тому

    What if i want to sum their data into 1 file

  • @gam3rman85
    @gam3rman85 9 місяців тому

    why are the files called AAPL if they are TSLA stock?

    • @RahulCKapatkar
      @RahulCKapatkar Місяць тому

      Becauseeeee !!!! ITTTT ITT ITTT DOESN'T MATTER WHAT YOU THINK IT IS !!!!!!!!!!!!!!!!! Cause Stone COLD SAID SO !!!!!

  • @nguyenduyta7136
    @nguyenduyta7136 2 роки тому +1

    Hi thank for your great videos. I have a question, if I have many csv file in one folder ( such as a list stock files A.csv, B.csv,…..) and now I would like to take one column of each files ( such as “close price” column) and finally concatenate all of them to one file. So how can I do

    • @jiejenn
      @jiejenn  2 роки тому

      You can combine all the files first into a master, then delete the columns you don't want.

    • @nguyenduyta7136
      @nguyenduyta7136 2 роки тому

      @@jiejenn hi Thank for your reply, by the way, I have many csv file A.csv, B.csv, C.csv, D.csv, E.csv,…. in one folder, but how can I use “for loop “ to pick automatically specified one ( B, C, D) only but not all of them ?

    • @mohammeddanishreza4902
      @mohammeddanishreza4902 Рік тому

      @@nguyenduyta7136 I think you can put the needed files name in a list and loop over the list.

  • @shomugger
    @shomugger 2 роки тому

    did the same code in VS code and got a lot of errors, where might be a problem?

  • @benmcdermott8575
    @benmcdermott8575 2 роки тому

    Do you know how to solve the issue of no such file or directory. Even though it does exist?

    • @jiejenn
      @jiejenn  2 роки тому

      Yes. The script cannot find the file.

  • @harithameka8328
    @harithameka8328 2 роки тому

    pandas.errors.EmptyDataError: No columns to parse from file
    i am getting this error
    how can i solve it sir

    • @jiejenn
      @jiejenn  2 роки тому

      Please Google the error for answers.

  • @asmitasubedi8215
    @asmitasubedi8215 3 роки тому

    What can I do to combine CSV files by column and not by row? I want more than 300 files combined side by side. I would appreciate it if you could answer. Thanks!

    • @jiejenn
      @jiejenn  3 роки тому

      Look into pandas concat method.

  • @antisunny9226
    @antisunny9226 2 роки тому

    How to get N number of csv files as user input ?

    • @jiejenn
      @jiejenn  2 роки тому

      Not sure if I understand your question.

    • @antisunny9226
      @antisunny9226 2 роки тому

      @@jiejenn HI, Thanks For immediate response.
      My query is i had some csv files , I need to take some of them as user input and combine them Into one single file and the perform some EDA.
      Like some times 3 files as user input
      Some files 5 files as user input.

  • @shabs_jovial
    @shabs_jovial 3 роки тому

    Can you please put a video on how to save multiple dataframe to a single zip using pandas without saving as CSV

    • @jiejenn
      @jiejenn  3 роки тому

      I don't think you can save a dataset as a zip file.

    • @shabs_jovial
      @shabs_jovial 3 роки тому

      @@jiejenn well we can by using compression='gzip' while we calling to_csv() .... But I could not find a feasible way to compress multiple df in a single zip

    • @alexybogomolov
      @alexybogomolov 3 роки тому

      @@shabs_jovial why don't you want to create the csv file first? Create it in other directory, use shutil.make_archive(output_filename, 'zip', dirname) to write the zip file, then delete the csv file.

    • @shabs_jovial
      @shabs_jovial 3 роки тому

      @@alexybogomolov Thanks for tip. But I have limited space and have abundant RAM and my result dataframe is more than a GB to save as CSV. Likewise i have multiple scripts running on this condition. So when I tried to save as CSV and run , my other scripts fail due to the restrictions of my space

  • @inaammuaz2284
    @inaammuaz2284 3 роки тому

    I dunno why, but mine is duplicated

    • @jiejenn
      @jiejenn  3 роки тому

      I dunno why either.

  • @Abhishekkumar-bl4kl
    @Abhishekkumar-bl4kl 2 роки тому

    hello sir, please make a video for .sav file combine using python

    • @jiejenn
      @jiejenn  2 роки тому

      Hum... Not interested. Thank you.

  • @whyleesworld2190
    @whyleesworld2190 3 роки тому

    Can you make this py file into a executable file? or use it as universal csv consolidator?

    • @jiejenn
      @jiejenn  3 роки тому

      You can make a Python program an executable file with pyinstaller.