Python Panda (Page: 5)
Export and Import Panda DataFrame to other formats
Saving panda DataFrame into a different file formats is very powerful and useful tool for further storage and presentation of these data.
Save panda to CSV file
CSV is a common file for storage table data
data = {'Number' : ['zero', 'one', 'two', 'three', 'four', 'five', 'six'],
'Roman' : ['O', 'I', 'II', 'III', 'IV', 'V', 'VI'],
'Arabic' : [0, 1, 2, 3, 4, 5, 6],
}
numbers_df = pd.DataFrame(data)
# write to CSV file
numbers_df.to_csv('dataset/numbers.csv',
index = False)
Read CSV file to panda DataFrame
Reading is very easy as well. For reading, it is possible to specify the separator, and also it is possible to give format of digits – some use coma instead of dot as a decimal separator. For example sep = ';' - this parameter will use ; as a separator. In fact you can use any symbol as a separator
# read from CSV file
df = pd.read_csv('dataset/numbers.csv')
Saving to Microsoft Excel tables
Microsoft Excel tables are very popular for data representation and for some analysis. Python can save panda DataFrame to Microsoft Excel tables
writer = pd.ExcelWriter('./dataset/numbers.xlsx', engine='xlsxwriter')
numbers_df.to_excel(writer, sheet_name='Sheet1')

Simple format of Microsoft Excel after panda DataFrame conversion
Saving to HTML
HTML is very popular format for presentation in the WEB. Panda DataFrame can be saved as HTML file.
numbers_df.to_html('./dataset/numbers.html',
index = False)

Simple HTML after panda DataFrame conversion
Go to Page: 1; 2; 3; 4; 5; 6; 7; 8;
Published: 2021-11-05 09:11:16
Updated: 2021-12-17 02:48:39