My Coding > Programming language > Python > Python libraries and packages > Python Panda

Python Panda (Page: 5)

Go to Page:

  1. Panda Series;
  2. Pandas DataFrame: Creation;
  3. Pandas: Create test DataFrame;
  4. Pandas DataFrame: Add/Remove;
  5. Pandas DataFrame: Export/Import;
  6. Panda search and select;
  7. Pandas Cheat Sheet;
  8. Pandas: MultiIndex DataFrame;

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')
Microsoft Exel
Microsoft Exel
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)
HTML file
HTML file
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

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.