How do I store a dataframe as an XLS in CDF files? I have to perform this within CDF functions.
Best answer by Ivar Stangeby
View originalHow do I store a dataframe as an XLS in CDF files? I have to perform this within CDF functions.
Best answer by Ivar Stangeby
View originalHello Eashwar!
You would have to deploy some Python code to do this - note I haven’t tested this, but it should serve as a starting point for you. This requires the library `openpyxl` to be able to call `df.to_excel`.
import pandas as pd
import io
def get_data_frame():
df = pd.DataFrame({
'A': [1, 2, 3],
'B': [4, 5, 6],
'C': ['p', 'q', 'r']
})
return df
def handle(client, data):
# do some set up to fetch the data-frame
dataframe = get_data_frame()
# then you can convert the dataframe to xls-format.
# to avoid storing directly to a file, we can use io.BytesIO()
output_buffer = io.BytesIO()
df.to_excel(output, sheet_name='my_sheet', index=False)
# the FilesAPI accepts BytesIO as input in `client.files.create`
client.files.upload_bytes(output_buffer, name="my_file", ...)
I hope this helps! Let me know if you need further assistance.
Hi
Yes
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.