Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
10402 Lượt xem

in python file for example,

file=field.Binary();

data=pandas.DataFrame(numpy.arange(16).reshape(4,4));


Now I want to save 'data' into 'file' as a excel file; how shall code for this?

in addition, shall I save a fig(which is plot by matplotlib.plot) into 'file' as a picture?



Ảnh đại diện
Huỷ bỏ
Tác giả

in xml file, the "file" is set as: <field name="file" widget="image" readonly="1" />, and I know widget="image" is for picture, so what for "excel file"?

Câu trả lời hay nhất

A Panda's DataFrame is not an excel spreadsheet on it's own. You have to first create the excel file, turn it into binary and then you can store it in your Binary field `file`.


However, if you want to edit an already existing excel spreadsheet on your computer you can simply do this:

import pandas as pd

# Create a Pandas dataframe from the data.
df = pd.DataFrame({'Data': [10, 20, 30, 20, 15, 30, 45]})

# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_simple.xlsx', engine='xlsxwriter')

# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1')

# Close the Pandas Excel writer and output the Excel file.
writer.save()

Source: http://xlsxwriter.readthedocs.io/working_with_pandas.html

There is much more information on the page that I am sure will be of use when solving your problem.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 22
2311
0
thg 7 19
2046
0
thg 10 15
2880
1
thg 4 24
4421
2
thg 2 23
8073