Home > Mobile >  In Julia, how to combine CSV file in given folder
In Julia, how to combine CSV file in given folder

Time:09-15

In Julia, here are tow questions:

  1. how to fid files list in folder D:\\working ? the files include "result_1.csv","result_2.csv","result_3.csv","result_4.csv"

  2. after using CSV.File to combine CSV file, the class is vector. how to union them into a big DataFrame?

using CSV
using DataFrames
pwd()
cd("D:\\working\\logistics\\logistics_bill\\V5")
total = CSV.File.(["result_1月.csv","result_2月.csv"]).|>DataFrame

CodePudding user response:

  1. To get the list of files in a directory use the readdir function. Then you can filter this list to keep only the files that match your needs. Alternatively you can use Glob.jl
  2. To combine data frames use reduce using vcat the data frames:
reduce(vcat, CSV.read.(["result_1月.csv","result_2月.csv"]))

(you might want to pass some keyword arguments if you want more fancy merging, like making a union of columns incase the CSV files do not have the same schema)

  • Related