Dataframe 使用Julia,如何读取多个CSV并合并列 我对朱丽亚很陌生,我认为自己是一个编程新手。我编写了一些MATLAB和Python代码
我有一堆CSV,我想把它们结合起来做数据分析。我的数据如下所示:Dataframe 使用Julia,如何读取多个CSV并合并列 我对朱丽亚很陌生,我认为自己是一个编程新手。我编写了一些MATLAB和Python代码,dataframe,julia,Dataframe,Julia,我有一堆CSV,我想把它们结合起来做数据分析。我的数据如下所示: using DataFrames using Plots using CSV using Glob using Pipe file_list = glob("*.csv") #list of all csvs in dir df = @pipe file_list[1] |> CSV.File(_,header = 2) |> DataFrame #Read file # I could have
using DataFrames
using Plots
using CSV
using Glob
using Pipe
file_list = glob("*.csv") #list of all csvs in dir
df = @pipe file_list[1] |> CSV.File(_,header = 2) |> DataFrame #Read file
# I could have use df = CSV.File(file_list[1], header = 2) |> DataFrame but
# I wanted to try piping multiple operation but it didn't work
[Results of the code snippet][1]
这导致:
问题是
谢谢。要对列表中的每个项目进行管道连接,请使用
。
julia> [1,2,3] .|> sqrt
3-element Array{Float64,1}:
1.0
1.4142135623730951
1.7320508075688772
您可以添加如下列:
julia> using DataFrames, Dates
julia> df = DataFrame("yr"=>2000, "m"=>1:2, "d"=>[30,1], "h"=>12:13, "min"=>30:31, "sec"=>58:59)
2×6 DataFrame
Row │ yr m d h min sec
│ Int64 Int64 Int64 Int64 Int64 Int64
─────┼──────────────────────────────────────────
1 │ 2000 1 30 12 30 58
2 │ 2000 2 1 13 31 59
julia> df[!,"datetime"] = DateTime.(df[!,"yr"], df[!,"m"], df[!,"d"], df[!,"h"], df[!,"min"], df[!,"sec"])
2-element Array{DateTime,1}:
2000-01-30T12:30:58
2000-02-01T13:31:59
julia> df[!,"file"] .= "file.csv"
2-element Array{String,1}:
"file.csv"
"file.csv"
julia> df
2×8 DataFrame
Row │ yr m d h min sec datetime file
│ Int64 Int64 Int64 Int64 Int64 Int64 DateTime String
─────┼─────────────────────────────────────────────────────────────────────────
1 │ 2000 1 30 12 30 58 2000-01-30T12:30:58 file.csv
2 │ 2000 2 1 13 31 59 2000-02-01T13:31:59 file.csv
非常感谢,我真的非常感谢您的快速和非常详细的解释!