-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPandaTools.py
More file actions
25 lines (21 loc) · 782 Bytes
/
PandaTools.py
File metadata and controls
25 lines (21 loc) · 782 Bytes
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
import pandas as pd
import os
class PandaTools:
@staticmethod
def open_df_in_libre_office(df: pd.DataFrame, path: str = 'assets/_temp', filetype: str = 'ods') -> None:
"""
Open a pandas DataFrame in LibreOffice Calc
:param df: the input dataframe
:param path: the path to save the file to (without file extension)
:param filetype: either 'csv' or 'ods'
"""
if filetype == 'csv':
path += '.csv'
df.to_csv(path, index=False)
elif filetype == 'ods':
path += '.ods'
df.to_excel(path, index=False)
else:
raise Exception(f'Unsupported file type {filetype}')
# Open file in LibreOffice Calc
os.system(f'soffice --calc {path} &')