Advertisement
elena1234

Read and Write to CSV file in Python

Apr 21st, 2022 (edited)
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | Source Code | 0 0
  1. import pandas as pd
  2.  
  3. # if you want to rename the column names
  4. df = pd.read_csv(r'C:/Users/eli/Desktop/listings.csv', skiprows = 3, skipfooter = 2, header = None, names = ['Survived','Age', 'Class', 'Gender', 'Ticket_price'])
  5.  
  6. # in JupyterLite
  7. df = pd.read_csv('movies_complete.csv',engine="python",on_bad_lines='skip', parse_dates=['release_date'])
  8. df.head()
  9.  
  10. # the df will has index "Athlete" and we will import only three columns
  11. df = pd.read_csv(r'summer_csv', index_col = "Athlete", usecols = ['Country', 'Name', 'Medals')
  12.  
  13. # write to csv file
  14. df.to_csv('new_df.csv', index = False)
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement