Showing posts with label DataFrames. Show all posts
Showing posts with label DataFrames. Show all posts

Julia language: DataFrames: insert a column

 The following code 

  1. inserts a new column into DataFrame named df
  2. inserts this column as a first (col_ind =1) column
  3. names this column Rata_Die
  4. populates the column values with an array of Int64 zeros (0)
  5. makes sure the name of the column is unique



col_ind = 1

insertcols!(df, col_ind, :Rata_Die => zeros(Int64, record_count); makeunique = true )



As an Amazon Associate I earn from qualifying purchases.

Julia language: DataFrames: insert a column

 The following code 

  1. inserts a new column into DataFrame named df
  2. inserts this column as a first (col_ind =1) column
  3. names this column Rata_Die
  4. populates the column values with an array of Int64 zeros (0)
  5. makes sure the name of the column is unique



col_ind = 1

insertcols!(df, col_ind, :Rata_Die => zeros(Int64, record_count); makeunique = true )



As an Amazon Associate I earn from qualifying purchases.

Julia DataFrames

 

Filtering DataFrame


New Syntax

 

Syntax explained:

  1. from original "data" (type DataFrames)
  2. create new "dataA" (type DataFrames)
  3. filter indices in column "Treatment" with values equal to "A"
  4. include ALL COLUMNS indicated by ":"
  5. Show the first 6 rows


dataA = data[isequal.(data.Treatment, "A"), : ] 

first(dataA, 6)



6 rows × 5 columns

AgeWCCCRPTreatmentResult
Int64Float64Int64StringString
13710.230AWorse
26710.470AWorse
34210.4100AStatic
45612.580AWorse
5609.50AStatic
66213.710AWorse

 


Deprecated Syntax

# dataA = data[data[:Treatment] .== "A", :] 

 

Warning: `getindex(df::DataFrame, col_ind::ColumnIndex)` is deprecated, use `df[!, col_ind]` instead.





As an Amazon Associate I earn from qualifying purchases.

Julia DataFrames

 

Filtering DataFrame


New Syntax

 

Syntax explained:

  1. from original "data" (type DataFrames)
  2. create new "dataA" (type DataFrames)
  3. filter indices in column "Treatment" with values equal to "A"
  4. include ALL COLUMNS indicated by ":"
  5. Show the first 6 rows


dataA = data[isequal.(data.Treatment, "A"), : ] 

first(dataA, 6)



6 rows × 5 columns

AgeWCCCRPTreatmentResult
Int64Float64Int64StringString
13710.230AWorse
26710.470AWorse
34210.4100AStatic
45612.580AWorse
5609.50AStatic
66213.710AWorse

 


Deprecated Syntax

# dataA = data[data[:Treatment] .== "A", :] 

 

Warning: `getindex(df::DataFrame, col_ind::ColumnIndex)` is deprecated, use `df[!, col_ind]` instead.





As an Amazon Associate I earn from qualifying purchases.

apt quotation..