Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Problems with first script: importing CSV-files to DataFrames and analyzing them

$
0
0

Hi!

I am trying to learn julia by importing the contents of CSV-files into DataFrames, and subsequently analyze the content. If I get this “base script” to work, I will probably repeatedly copy it and use it for different projects, so I would like it to have a good and lasting quality.

using CSV
using DataFrames
using Dates

data_import = CSV.File(	"file_csv.csv",
						delim=",",
						ignoreemptylines=true,
						header=false);

data_dataset = DataFrame();
data_dataset.Column1 = data_import.Column1;
data_dataset.Column2 = data_import.Column2;
data_dataset.Column3 = length(data_dataset.Column2);
data_dataset.Column4 = sort(data_dataset.Column2);
#sort!(data_dataset, :Column2, rev=false);
data_dataset = select(data_dataset, [:Column4, :Column3, :Column2, :Column1]);

println(data_dataset);

I have a few problems and questions:

  • First of all: would you say that seem like a sensible way to import CSV-files into julia? What are the most obvious flaws and amateur-signs of my code?
  • How do I manually add or change column names?
  • How do I specify what type the content of a column should be interpreted as?
  • The line ‘data_dataset.Column3 = length(data_dataset.Column1);’ gives me a deprecation warning. What syntax should I use instead?
  • The content of the line ‘data_dataset.Column4 = sort(data_dataset.Column2);’ does not result in a deprecation warning, even though the syntax seems identical to the previous line. Why is this?
  • The commented out line ‘sort!(data_dataset, :Column2, rev=false);’ just results in an error. How do I sort in a way that make all the rows change order according to my sorting? I.E, sort all rows according to the content of a single column?
  • Not a part of the above mentioned code, but how do I replace the values of cells in specified columns with “missing”?

7 posts - 7 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles