import pandas as pd

Input and Output – Reading and Writing DataΒΆ

Pandas provides robust support for reading data from and writing data to many formats. This notebook demonstrates reading CSV files from URLs with pd.read_csv(), exporting DataFrames to CSV with .to_csv() (including controlling index output and encoding), reading multi-sheet Excel workbooks with pd.read_excel() and the sheetname parameter, and writing to Excel using pd.ExcelWriter(). Understanding I/O operations is essential for building data pipelines that ingest data from external sources and produce outputs for downstream systems.

t = pd.read_csv("https://data.cityofnewyork.us/api/views/ic3t-wcy2/rows.csv").head()
pd.read_csv("https://data.cityofnewyork.us/api/views/ic3t-wcy2/rows.csv").head(2)
t.to_csv("test_Export.csv")
t.to_csv("test_Export.csv",index=False)
crime_india = pd.read_csv("https://data.gov.in/node/4223881/datastore/export/csv")
crime_india.to_csv("crime_india.csv",index=False,encoding="UTF8")
pd.read_excel("Data - Multiple Worksheets.xlsx")
pd.read_excel("Data - Multiple Worksheets.xlsx", sheetname=1)
pd.read_excel("Data - Multiple Worksheets.xlsx", sheetname=[0,1])
state = crime_india["State/UT (Col.3)"]
excel_file = pd.ExcelWriter("State Name.xlsx")
state.to_excel(excel_file,index=False)
excel_file.save()