itorch_notebook_df_test



In [ ]:
require 'torch'
require 'lfs'

-- Make sure that directory structure is always the same
if (string.match(lfs.currentdir(), "/specs/output$")) then
  lfs.chdir("../..")
end

paths.dofile(lfs.currentdir() .. '/init.lua')

-- Go into tests so that the loading of CSV:s is the same as always
lfs.chdir("./specs/")

In [ ]:
itorch ~= nil

In [ ]:
-- A quick way to get a feeling for how the __tostring method works
a = Dataframe('./data/simple_short.csv')

In [ ]:
print("-- Regular print with a Dataframe --")
print(a)

In [ ]:
print("  -- Check regular table --  ")
print({1, 2, 3, {1,2,3, {4,5,6}}})

In [ ]:
print("-- Long table --")
local a = Dataframe()
a:load_csv{path = "data/realistic_29_row_data.csv",
           verbose = false}

math.randomseed(10)
left_right = {}
for i = 1,a:shape()["rows"] do
  if (math.random() > 0.5) then
    table.insert(left_right, "left")
  else
    table.insert(left_right, "right")
  end
end
a:add_column("Side", Df_Array(left_right))
a:output()

In [ ]:
local a = Dataframe()
a:load_csv{path = "data/realistic_29_row_data.csv",
           verbose = false}
a:as_categorical("Gender")
print("With set number of digits")
a:output{digits = 1}

In [ ]: