文件读取 pandas.read_csv

pandas.read_csv(filepath_or_buffer, 
				sep=NoDefault.no_default, 
				delimiter=None, 
				header='infer', 
				names=NoDefault.no_default, 
				index_col=None, 
				usecols=None, 
				squeeze=None, 
				prefix=NoDefault.no_default, 
				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=None, 
				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='.', 
				lineterminator=None, 
				quotechar='"', 
				quoting=0, 
				doublequote=True, 
				escapechar=None, 
				comment=None, 
				encoding=None, 
				encoding_errors='strict', 
				dialect=None, 
				error_bad_lines=None, 
				warn_bad_lines=None, 
				on_bad_lines=None, 
				delim_whitespace=False, 
				low_memory=True, 
				memory_map=False, 
				float_precision=None, 
				storage_options=None)

参数

返回值
DataFrame or TextParser

import pandas as pd
pd.read_csv('data.csv')

分块读入文件

  1. 读取前五行,指明nrows=5
import pandas as pd

df = pd.read_csv('test.csv', nrows=5)

pandas.DataFrame.to_csv

DataFrame.to_csv(path_or_buf=None, 
				sep=',', 
				na_rep='', 
				float_format=None, 
				columns=None, 
				header=True, 
				index=True, 
				index_label=None, 
				mode='w', 
				encoding=None, 
				compression='infer', 
				quoting=None, 
				quotechar='"', 
				line_terminator=None, 
				chunksize=None, 
				date_format=None, 
				doublequote=True, 
				escapechar=None, 
				decimal='.', 
				errors='strict', 
				storage_options=None)

参数

返回值
None or str

df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
                   'mask': ['red', 'purple'],
                   'weapon': ['sai', 'bo staff']})
df.to_csv(index=False)
# 'name,mask,weaponnRaphael,red,sainDonatello,purple,bo staffn'

原文地址:https://blog.csdn.net/weixin_43956958/article/details/125881300

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_18351.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注