Create a new Frame that points to a dataframe in memory. All frames are stored in ``Frame.frames``. Names must be unique. Parameters ---------- name : str Frame key. space : alphapy.Space Namespace of the given frame. df : pandas.DataFrame The content
| 74 | # |
| 75 | |
| 76 | class Frame(object): |
| 77 | """Create a new Frame that points to a dataframe in memory. All |
| 78 | frames are stored in ``Frame.frames``. Names must be unique. |
| 79 | |
| 80 | Parameters |
| 81 | ---------- |
| 82 | name : str |
| 83 | Frame key. |
| 84 | space : alphapy.Space |
| 85 | Namespace of the given frame. |
| 86 | df : pandas.DataFrame |
| 87 | The contents of the actual dataframe. |
| 88 | |
| 89 | Attributes |
| 90 | ---------- |
| 91 | frames : dict |
| 92 | Class variable for storing all known frames |
| 93 | |
| 94 | Examples |
| 95 | -------- |
| 96 | |
| 97 | >>> Frame('tech', Space('stock', 'prices', '5m'), df) |
| 98 | |
| 99 | """ |
| 100 | |
| 101 | # class variable to track all frames |
| 102 | |
| 103 | frames = {} |
| 104 | |
| 105 | # __init__ |
| 106 | |
| 107 | def __init__(self, |
| 108 | name, |
| 109 | space, |
| 110 | df): |
| 111 | # code |
| 112 | if df.__class__.__name__ == 'DataFrame': |
| 113 | fn = frame_name(name, space) |
| 114 | if not fn in Frame.frames: |
| 115 | self.name = name |
| 116 | self.space = space |
| 117 | self.df = df |
| 118 | # add frame to frames list |
| 119 | Frame.frames[fn] = self |
| 120 | else: |
| 121 | logger.info("Frame ", fn, " already exists") |
| 122 | else: |
| 123 | logger.info("df must be of type Pandas DataFrame") |
| 124 | |
| 125 | # __str__ |
| 126 | |
| 127 | def __str__(self): |
| 128 | return frame_name(self.name, self.space) |
| 129 | |
| 130 | |
| 131 | # |