forked from OpenFAST/python-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparquet_file.py
More file actions
48 lines (33 loc) · 1.09 KB
/
parquet_file.py
File metadata and controls
48 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas as pd
from .file import File
class ParquetFile(File):
@staticmethod
def defaultExtensions():
return ['.parquet']
@staticmethod
def formatName():
return 'Parquet file'
def __init__(self,filename=None,**kwargs):
self.filename = filename
if filename:
self.read(**kwargs)
def _read(self):
""" use pandas read_parquet function to read parquet file"""
self.data=pd.read_parquet(self.filename)
def _write(self):
""" use pandas DataFrame.to_parquet method to write parquet file """
self.data.to_parquet(path=self.filename)
def toDataFrame(self):
#already stored as a data frame in self.data
#just return self.data
return self.data
def fromDataFrame(self, df):
#data already in dataframe
self.data = df
def toString(self):
""" use pandas DataFrame.to_string method to convert to a string """
s=self.data.to_string()
return s
def __repr__(self):
s ='Class Parquet (attributes: data)\n'
return s