상세 컨텐츠

본문 제목

How to use 'read_csv()' in pandas package?

커리어리뷰

by 자연키 2023. 2. 21. 08:28

본문

Pandas read_csv() function is one of the most commonly used functions for importing data from a CSV file into a DataFrame. The function provides several optional parameters that can be used to customize the import process. Here are some of the most commonly used parameters of the read_csv() function:


  • filepath_or_buffer: This parameter specifies the file path or URL of the CSV file to be read. It can be a string or a file-like object.
  • sep: This parameter specifies the delimiter used in the CSV file. By default, it is set to ',' (comma-separated values).
  • header: This parameter specifies which row of the CSV file should be used as the column names. By default, it is set to 'infer', which means that pandas will try to automatically determine the header row. If the header is not in the first row of the CSV file, you can specify the row number by setting this parameter to an integer.
  • index_col: This parameter specifies which column of the CSV file should be used as the index column of the DataFrame. By default, the index column is not set.
  • usecols: This parameter specifies which columns of the CSV file should be read into the DataFrame. It can be a list of column names or column indices. By default, all columns are read.
  • dtype: This parameter specifies the data type of the columns. It can be a dictionary with column names as keys and data types as values, or it can be a string that specifies the data type of all columns.
  • na_values: This parameter specifies the values that should be treated as missing values (NaN) in the DataFrame. It can be a list of strings or a dictionary with column names as keys and lists of values as values.

These are just some of the most commonly used parameters of the read_csv() function. The read_csv() function provides many other parameters that can be used to customize the import process, such as encoding, skiprows, nrows, and parse_dates. It's important to consult the pandas documentation for a full list of available parameters and their usage.

반응형

관련글 더보기

댓글 영역