Python ProgrammingPython Programming

How to Writing DataFrame to CSV file in Pandas?

Writing DataFrame to CSV file:

import pandas as pd

df = pd.DataFrame({'DateOfBirth': ['1986-11-11', '1999-05-12', '1976-01-01',
                                   '1986-06-01', '1983-06-04', '1990-03-07',
                                   '1999-07-09'],
                   'State': ['NY', 'TX', 'FL', 'AL', 'AK', 'TX', 'TX']
                   },
                  index=['Jane', 'Pane', 'Aaron', 'Penelope', 'Frane',
                         'Christina', 'Cornelia'])

df.to_csv('test.csv', encoding='utf-8', index=True)