python中pd读取csv二进制_python用pd.read_csv()方法来读取csv文件

本文详细介绍了如何使用pandas的pd.read_csv()函数读取CSV文件,包括不设置表头、自定义列名、设置索引、指定分隔符以及处理缺失数据等操作。
摘要由CSDN通过智能技术生成

importpandas as pdprint("************取消第一行作为表头*************")

data2= pd.read_csv('rating.csv',header=None)print("************为各个字段取名**************")

data3= pd.read_csv('rating.csv',names=['user_id','book_id','rating'])print("***********将某一字段设为索引***************")

data3= pd.read_csv('rating.csv',

names=['user_id','book_id','rating'],

index_col= "user_id")print("************用sep参数设置分隔符**************")

data4= pd.read_csv('rating.csv',

names=['user_id','book_id','rating'],

sep=',')print("************自动补全缺失数据为NaN**************")

data5= pd.read_csv('data.csv',header=None)

read_csv(filepath_or_buffer: Union[ForwardRef('PathLike[str]'), str, IO[~T], io.RawIOBase, io.BufferedIOBase, io.TextIOBase, _io.TextIOWrapper, mmap.mmap], sep=, delimiter=None, header='infer', names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, skipfooter=0, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, cache_dates=True, iterator=False, chunksize=None, compression='infer', thousands=None, decimal: str = '.', lineterminator=None, quotechar='"', quoting=0, doublequote=True, escapechar=None, comment=None, encoding=None, dialect=None, error_bad_lines=True, warn_bad_lines=True, delim_whitespace=False, low_memory=True, memory_map=False, float_precision=None, storage_options: Union[Dict[str, Any], NoneType] = None)

Read a comma-separated values (csv) file into DataFrame.

Also supports optionally iterating or breaking of the file

into chunks.

Additional help can be found in the online docs for

`IO Tools `_.

Parameters

----------

filepath_or_buffer : str, path object or file-like object

Any valid string path is acceptable. The string could be a URL. Valid

URL schemes include http, ftp, s3, gs, and file. For file URLs, a host is

expected. A local file could be: file://localhost/path/to/table.csv.

If you want to pass in a path object, pandas accepts any ``os.PathLike``.

By file-like object, we refer to objects with a ``read()`` method, such as

a file handle (e.g. via builtin ``open`` function) or ``StringIO``.

sep : str, default ','

Delimiter to use. If sep is None, the C engine cannot automatically detect

the separator, but the Python parsing engine can, meaning the latter will

be used and automatically detect the separator by Python's builtin sniffer

tool, ``csv.Sniffer``. In addition, separators longer than 1 character and

different from ``'\s+'`` will be interpreted as regular expressions and

will also force the use of the Python parsing engine. Note that regex

delimiters are prone to ignoring quoted data. Regex example: ``'\r\t'``.

delimiter : str, default ``None``

Alias for sep.

header : int, list of int, default 'infer'

Row number(s) to use as the column names, and the start of the

data.  Default behavior is to infer the column names: if no names

are passed the behavior is identical to ``header=0`` and column

names are infer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值