Skip to content

Latest commit

 

History

History
200 lines (133 loc) · 6.72 KB

README.md

File metadata and controls

200 lines (133 loc) · 6.72 KB

DataFrame

Matlab impelementation of DataFrame/Pandas concept. This project wraps and makes use of as much as possible of the Matlab table, but with the intent of providing a class implementation that could be specialized further.

</style>

Create a DataFrame from scratch

The DataFrame is created in the same exact way as a table. The constructor just passes the arguements to the table constructor, then stores the table as as private property. We can still retrieve table properties

df = DataFrame(0, 0, 0, 0, ...
'VariableNames', {'test1', 'test2','test3','test4',});
df.Properties
ans =

         Description: ''
VariableDescriptions: {}
       VariableUnits: {}
      DimensionNames: {'Row'  'Variable'}
            UserData: []
            RowNames: {}
       VariableNames: {'test1'  'test2'  'test3'  'test4'}

View the DataFrame the Same as a Table

DataFrame overrides the display method to show the table instead of the DataFrame object

df
df =

test1    test2    test3    test4
_____    _____    _____    _____

0        0        0        0    

Access Table Columns Through DataFrame

The column names are pass throughs into the actual table structure. We can access the column as normal

df.test1
df.test3
ans =

 0

ans =

 0

Access Methods Attached to the DataFrame Object

You no longer need to know which possible functions you can use on a Matlab table. They are available to use either way.

df.height()
height(df)
ans =

 1

ans =

 1

Extend DataFrame However We'd Like

Matlab blocks you from extending the table data structure, but we can get around that with this approach

df = DataFrame.fromCSV(which('ugly_data.csv'));
df.head();
         Name          Zeros      Lat         Lng         Normal       Negative
_______________    _____    ________    ________    ___________    ________

'Connor Hayden'    0        -2.58201    71.06714    0.006049531    3       


                 GUID                           Date           Timestamp 
______________________________________    _________________    __________

'7B79A197-E85F-2BFF-F37E-727DEDAC9803'    'April 27th 2015'    1394414933


AlphaNumeric 
_____________

'FSU09MJG3ZB'

Or, if You Still Want to See the Object

Column data will show empty since we are just dynamically passing through them on each subscript call. Properties shows up with contents, since it uses a getter method

df.details();
  DataFrame with properties:

  Properties: [1x1 struct]
      Normal: []
         Lng: []
    Negative: []
       Zeros: []
        Name: []
AlphaNumeric: []
        Date: []
        GUID: []
         Lat: []
   Timestamp: []

     Name          Zeros      Lat         Lng         Normal       Negative
_______________    _____    ________    ________    ___________    ________

'Connor Hayden'    0        -2.58201    71.06714    0.006049531    3       


                 GUID                           Date           Timestamp 
______________________________________    _________________    __________

'7B79A197-E85F-2BFF-F37E-727DEDAC9803'    'April 27th 2015'    1394414933


AlphaNumeric 
_____________

'FSU09MJG3ZB'

Variables:

Name: 20400x1 cell string

Zeros: 20400x1 double
    Values:

        min       0      
        median    0      
        max       0      

Lat: 20400x1 double
    Values:

        min       -89.42406
        median     -1.02059
        max        88.89347

Lng: 20400x1 double
    Values:

        min       -177.18611
        median      0.934815
        max         176.4439

Normal: 20400x1 double
    Values:

        min       -0.543252895
        median    -0.017611593
        max        0.573277103

Negative: 20400x1 double
    Values:

        min        -5       
        median    0.5       
        max         5       

GUID: 20400x1 cell string

Date: 20400x1 cell string

Timestamp: 20400x1 double
    Values:

        min         1378967930
        median    1403645750.5
        max         1439505058

AlphaNumeric: 20400x1 cell string

We Can Try the Same Thing on a Standard Table

tbl = readtable(which('ugly_data.csv'));
try
tbl.head();
head(tbl);
catch err
disp(err.message)
end
Unrecognized variable name 'head'.

Dynamically add columns to the DataFrame

df.Lat2 = df.Lat;
df.Lat3 = df.Lat;
df.columns()
ans =

Columns 1 through 7

'Name'    'Zeros'    'Lat'    'Lng'    'Normal'    'Negative'    'GUID'

Columns 8 through 12

'Date'    'Timestamp'    'AlphaNumeric'    'Lat2'    'Lat3'

Easily remove columns from the DataFrame

df.remove_cols({'Lat2', 'Lat3'});
df.columns()
ans =

Columns 1 through 7

'Name'    'Zeros'    'Lat'    'Lng'    'Normal'    'Negative'    'GUID'

Columns 8 through 10

'Date'    'Timestamp'    'AlphaNumeric'

Initial Start at Providing Complete Wrapper for Table

methods('DataFrame')
Methods for class DataFrame:

DataFrame disp is_column subsref toStruct
addprop getTable numel summary width
columns head remove_cols toArray writetable
details height subsasgn toCell

Static methods:

fromArray fromCell intersect rowfun
fromCSV fromStruct ismember varfun

Call "methods('handle')" for methods of DataFrame inherited from handle.