dataFrame.hpp
1 #ifndef MARIAN_DATAFRAME_HPP
2 #define MARIAN_DATAFRAME_HPP
3 
4 #include <string>
5 #include <vector>
6 #include <iostream>
7 #include <map>
8 
9 namespace marian {
10  class DataEntryClerk;
11 
22  class DataFrame {
23  public:
24  DataFrame(){};
25  DataFrame(std::string file_name, char delimiter, bool first_row_is_column_names, int primery_key = 0);
26 
27  std::string operator()(const int col, const int row);
28  std::string operator()(const std::string col, const int row);
29  std::string operator()(const std::string col, const std::string row);
30 
31  std::vector<std::string> operator()(int col);
32  std::vector<std::string> operator()(std::string col);
33 
34  double getNumber(const int col, const int row);
35  double getNumber(const std::string col, const int row);
36  double getNumber(const std::string col, const std::string row);
37 
38  std::vector<std::string> getColumnNames() const;
39  std::vector<std::string> getPrimaryKeys() const;
40  std::map<std::string, std::string> getRow(int row) const;
41 
42  void append(const DataEntryClerk&);
43  void append(const DataFrame&);
44 
45  void print(int n_rows = -1);
46  void printToCsv(std::string file_name, char delimiter = ';');
47 
48  int getNumberOfRows() const;
49  int getNumberOfColumns() const;
50 
51  friend std::ostream& operator<<(std::ostream&, DataFrame&);
52  private:
53  void parseFile(std::string file_name, char delimiter);
54  void createColumnNames(bool first_row);
55 
56  std::vector<std::vector<std::string> > data_;
57  std::map<std::string,int> column_names_;
58  std::map<std::string,int> primary_key_;
59  int ncols_ = 0;
60  int nrows_ = 0;
61  };
62 
70  public:
71 
75  void add(std::string, std::string);
76  void add(std::string, double);
77  void add(std::string, int);
78 
83  template<typename T>
84  void add(const std::map<std::string, T>& input) {
85  for (auto item : input)
86  add(item.first, item.second);
87  }
88 
89  friend class DataFrame;
90  private:
91  std::map<std::string, std::string> data_;
92  };
93 } // namespace marian
94 
95 #endif /* MARIAN_DATAFRAME_HPP */
DataEntryClerk()
Default constructor.
Definition: dataFrame.hpp:74
std::vector< std::string > getColumnNames() const
Returns column names as vector of strings.
Definition: dataFrame.cpp:299
std::map< std::string, int > column_names_
Maps column name to column number.
Definition: dataFrame.hpp:57
std::map< std::string, std::string > getRow(int row) const
Returns row in form of std::map.
Definition: dataFrame.cpp:327
std::string operator()(const int col, const int row)
Reads cell in c-th column and r-th row.
Definition: dataFrame.cpp:89
int getNumberOfRows() const
Returns number of rows.
Definition: dataFrame.cpp:315
int nrows_
number of rows
Definition: dataFrame.hpp:60
friend std::ostream & operator<<(std::ostream &, DataFrame &)
Overloads stream operator.
Definition: dataFrame.cpp:351
int getNumberOfColumns() const
Returns number of columns.
Definition: dataFrame.cpp:321
void parseFile(std::string file_name, char delimiter)
parse csv file, result of method is saved in DataFrame::data_
Definition: dataFrame.cpp:39
std::map< std::string, int > primary_key_
Maps row name to row number.
Definition: dataFrame.hpp:58
Definition: backwardKolmogorovEq.cpp:5
void createColumnNames(bool first_row)
creates columns names basing on the first row of csv file
Definition: dataFrame.cpp:67
void print(int n_rows=-1)
Prints dataframe.
Definition: dataFrame.cpp:202
std::vector< std::vector< std::string > > data_
Holds data as 2d table of strings.
Definition: dataFrame.hpp:56
void append(const DataEntryClerk &)
adds data stored by DataEntryClerk
Definition: dataFrame.cpp:172
std::vector< std::string > getPrimaryKeys() const
Returns primary keys as vector of strings.
Definition: dataFrame.cpp:289
Class used to handle data.
Definition: dataFrame.hpp:22
void add(const std::map< std::string, T > &input)
add a map to data
Definition: dataFrame.hpp:84
int ncols_
number of columns
Definition: dataFrame.hpp:59
std::map< std::string, std::string > data_
Maps that stores inputs provided using method DataEntryClerk::add.
Definition: dataFrame.hpp:91
double getNumber(const int col, const int row)
Reads cell in c-th column and r-th row.
Definition: dataFrame.cpp:143
Class used to provide data to julian::DataFrame.
Definition: dataFrame.hpp:69
void printToCsv(std::string file_name, char delimiter= ';')
prints dataframe to csv file
Definition: dataFrame.cpp:258