YouTip LogoYouTip

Pandas Io Api Reference

Pandas Input/Output (I/O) API Manual

Pandas Input/Output (I/O) API Manual

Pandas is a powerful Python data analysis library that provides a large number of data manipulation tools, including data input and output (I/O).

The following are the commonly used Pandas Input/Output (I/O) APIs:

**Reading Data**

Method Description
pd.read_csv(filepath, sep, header, index_col) Read data from CSV file.
pd.read_excel(io, sheet_name) Read data from Excel file.
pd.read_json(path_or_buf) Read data from JSON file.
pd.read_html(io) Read table data from HTML file.
pd.read_sql(sql, con) Read data from SQL database.
pd.read_clipboard() Read data from clipboard.
pd.read_parquet(path) Read data from Parquet file.
pd.read_feather(path) Read data from Feather file.
pd.read_hdf(path, key) Read data from HDF5 file.
pd.read_pickle(path) Read data from Pickle file.
pd.read_sas(filepath) Read data from SAS file.
pd.read_spss(filepath) Read data from SPSS file.
pd.read_sql_table(table_name, con) Read data from table in SQL database.
pd.read_sql_query(sql, con) Execute SQL query and read results.
pd.read_gbq(query) Read data from Google BigQuery.

**Writing Data**

Method Description
DataFrame.to_csv(path, sep, index) Write DataFrame to CSV file.
DataFrame.to_excel(path, sheet_name) Write DataFrame to Excel file.
DataFrame.to_json(path) Write DataFrame to JSON file.
DataFrame.to_html(path) Write DataFrame to HTML file.
DataFrame.to_sql(name, con) Write DataFrame to SQL database.
DataFrame.to_clipboard() Copy DataFrame to clipboard.
DataFrame.to_parquet(path) Write DataFrame to Parquet file.
DataFrame.to_feather(path) Write DataFrame to Feather file.
DataFrame.to_hdf(path, key) Write DataFrame to HDF5 file.
DataFrame.to_pickle(path) Write DataFrame to Pickle file.
DataFrame.to_markdown(path) Write DataFrame to Markdown file.
DataFrame.to_string() Convert DataFrame to string.
DataFrame.to_latex(path) Write DataFrame to LaTeX file.
DataFrame.to_records() Convert DataFrame to numpy record array.
DataFrame.to_dict() Convert DataFrame to dictionary.
DataFrame.to_numpy() Convert DataFrame to numpy array.

Examples

Examples

import pandas as pd

# Read CSV file
df = pd.read_csv('data.csv')

# Read Excel file
df_excel = pd.read_excel('data.xlsx', sheet_name='Sheet1')

# Read JSON file
df_json = pd.read_json('data.json')

# Write to CSV file
df.to_csv('output.csv', index=False)

# Write to Excel file
df.to_excel('output.xlsx', sheet_name='Sheet1')

# Write to JSON file
df.to_json('output.json')

**Detailed Parameter Description**

pd.read_csv()

Parameter Description
filepath File path.
sep Delimiter, default is ,.
header Specify the row number used as column names, default is 0 (first row).
index_col Specify the column number or column name used as index.
dtype Specify data types for columns.
na_values Specify which values should be treated as missing values.

DataFrame.to_csv()

Parameter Description
path File path.
sep Delimiter, default is ,.
index Whether to write index, default is True.
header Whether to write column names, default is True.
encoding File encoding, default is utf-8.

pd.read_excel()

Parameter Description
io File path or file object.
sheet_name Worksheet name or index, default is 0.
header Specify the row number used as column names, default is 0.
index_col Specify the column number or column name used as index.

DataFrame.to_excel()

Parameter Description
path File path.
sheet_name Worksheet name, default is Sheet1.
index Whether to write index, default is True.
header Whether to write column names, default is True.

For more detailed information, please refer to Pandas Official Documentation.

← Pandas Arrays Scalars Data TypPandas Series Api Reference β†’