本文整理汇总了Python中pandas.to_csv方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.to_csv方法的具体用法?Python pandas.to_csv怎么用?Python pandas.to_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.to_csv方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_csv [as 别名]
def execute(self, context):
mysql_hook = MySqlHook(mysql_conn_id=self.mysql_conn_id)
s3_conn = S3Hook(aws_conn_id=self.aws_conn_id, verify=self.verify)
data_df = mysql_hook.get_pandas_df(self.query)
self.log.info("Data from MySQL obtained")
self._fix_int_dtypes(data_df)
with NamedTemporaryFile(mode='r+', suffix='.csv') as tmp_csv:
data_df.to_csv(tmp_csv.name, **self.pd_csv_kwargs)
s3_conn.load_file(filename=tmp_csv.name,
key=self.s3_key,
bucket_name=self.s3_bucket)
if s3_conn.check_for_key(self.s3_key, bucket_name=self.s3_bucket):
file_location = os.path.join(self.s3_bucket, self.s3_key)
self.log.info("File saved correctly in %s", file_location)
示例2: default_csv_writer
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_csv [as 别名]
def default_csv_writer(df, csvfile, **kwargs):
"""
Default function for writing a csv file.
Wrapper around the standard pandas pd.to_csv() function, but with
slightly different defaults:
- index is ``False``
- encoding is ``utf-8``
"""
options = {
'index': False,
'encoding': 'utf-8',
}
options.update(kwargs)
if sys.version_info[0] > 2 and len(df) > 0:
bytes_cols = find_bytes_cols(df)
if bytes_cols:
df = bytes_to_unicode(df, bytes_cols)
return df.to_csv(csvfile, **options)
示例3: write
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_csv [as 别名]
def write(self, ds_uri):
pd.to_csv(ds_uri)
# Generic update function
示例4: write
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import to_csv [as 别名]
def write(self, ds_uri):
pd.to_csv(ds_uri)
# ToDo: Generic update function