Skip to content

Python Pandas 1

_#python

working with CSV files

  • export to csv/json/excel/sql:
df.to_csv(path)
df.to_json(path)
df.to_excel(path)
df.to_sql(path)
  • import from csv/json/excel/sql:
df.from_csv(path)
df.from_json(path)
df.from_excel(path)
df.from_sql(path)

Note that the path should include the file name(and extension)

  • specify the headers:
  • declare headers as a list: headers = ["col_name_1", "col_name_2", ...]
  • set the column headers: df.columns = headers

  • some other info on data:

Command Description
df.head() get the first 5 rows of data
df.tail() get the last 5 rows
df.types() get a list of columns and each column's data type
df.describe() get a statistical summary
df.info() get a concise summary

*ref: Pandas Documentation