Reading CSV Files #
Reading a CSV file in Pandas is very straightforward. All you need is:
df = pd.read_csv("path")
This single line loads the CSV file. By default, Pandas uses the first row of the file as column headers. If the CSV file has no header row, you can specify:
df = pd.read_csv("path", header=None)
By default, the first column is not used as the index. If you want to use a specific column as the index:
df = pd.read_csv("path", index_col="column_name")
Displaying Data #
When the file contains many columns, Pandas may truncate the display and hide some columns. If you want to see all columns, you can use:
pd.set_option("display.max_columns", num)
Where num
is the number of columns you want to show.
Sometimes, a column contains values that are too long and get truncated. To change the maximum column width shown:
pd.set_option("display.max_colwidth", num)