本文整理汇总了Python中csv.QUOTE_NONNUMERIC属性的典型用法代码示例。如果您正苦于以下问题:Python csv.QUOTE_NONNUMERIC属性的具体用法?Python csv.QUOTE_NONNUMERIC怎么用?Python csv.QUOTE_NONNUMERIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类csv
的用法示例。
在下文中一共展示了csv.QUOTE_NONNUMERIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_denominator_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def get_denominator_csv(self):
output = io.StringIO()
writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(["year", "month", "officers out on service"])
values = sorted(self.denominator_values,
key=lambda x: (x.year, x.month))
for value in values:
row = [
value.year,
value.month,
value.officers_out_on_service
]
writer.writerow(row)
return output.getvalue()
示例2: writerow
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def writerow(self, row):
def _check_as_is(x):
return (self.quoting == csv.QUOTE_NONNUMERIC and
is_number(x)) or isinstance(x, str)
row = [x if _check_as_is(x)
else pprint_thing(x).encode("utf-8") for x in row]
self.writer.writerow([s for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and re-encode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
示例3: writerows
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def writerows(self, rows):
def _check_as_is(x):
return (self.quoting == csv.QUOTE_NONNUMERIC and
is_number(x)) or isinstance(x, str)
for i, row in enumerate(rows):
rows[i] = [x if _check_as_is(x)
else pprint_thing(x).encode("utf-8") for x in row]
self.writer.writerows([[s for s in row] for row in rows])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and re-encode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
示例4: writerow
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def writerow(self, row):
def _check_as_is(x):
return (self.quoting == csv.QUOTE_NONNUMERIC and
is_number(x)) or isinstance(x, str)
row = [x if _check_as_is(x)
else pprint_thing(x).encode('utf-8') for x in row]
self.writer.writerow([s for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
示例5: writerows
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def writerows(self, rows):
def _check_as_is(x):
return (self.quoting == csv.QUOTE_NONNUMERIC and
is_number(x)) or isinstance(x, str)
for i, row in enumerate(rows):
rows[i] = [x if _check_as_is(x)
else pprint_thing(x).encode('utf-8') for x in row]
self.writer.writerows([[s for s in row] for row in rows])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream
self.stream.write(data)
# empty queue
self.queue.truncate(0)
示例6: save_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def save_csv(matrix, output_directory, output_file_name):
"""
Saves the input matrix as a CSV File
Args:
matrix(list): an array containing data to be saved
output_drectory(str): location to save graph
output_file_name(str): name of the csv file to be saved
Returns:
null
"""
if config.DEBUGGER:
print "Generating", (output_file_name + ".csv")
check_if_dir_exists(output_directory) #create output directory if doesn't exist
output_file = output_directory + "/" + output_file_name +".csv"
with open(output_file, 'wb') as myfile:
wr = csv.writer(myfile, quoting=csv.QUOTE_NONNUMERIC)
if matrix is not None:
for col in matrix:
wr.writerow(col)
示例7: setup_writer
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def setup_writer(fileid, postfix):
"""Use to prepare file and writer for data logging
Arguments:
fileid (string): unique file identfier
postfix (string): path
"""
# we dump episode num, step, total reward, and
# number of episodes solved in a csv file for analysis
csvfilename = "%s.csv" % fileid
csvfilename = os.path.join(postfix, csvfilename)
csvfile = open(csvfilename, 'w', 1)
writer = csv.writer(csvfile,
delimiter=',',
quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(['Episode',
'Step',
'Total Reward',
'Number of Episodes Solved'])
return csvfile, writer
开发者ID:PacktPublishing,项目名称:Advanced-Deep-Learning-with-Keras,代码行数:22,代码来源:policygradient-car-10.1.1.py
示例8: gen_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def gen_csv(csvdata):
headerline = csvdata[0].keys()
if PY3:
output = io.StringIO()
else:
output = io.BytesIO()
headerline = [l.encode('utf-8') for l in headerline]
writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC)
writer.writerow(headerline)
for rk in csvdata:
rkline = []
for l in rk.values():
if l is None:
rkline.append("")
elif isinstance(l, (int, float, datetime)):
rkline.append(l)
else:
rkline.append(l.encode('utf-8'))
writer.writerow(rkline)
return output.getvalue()
# ------ EVENT INFORMATION ---------
# API: Outputs JSON about the current event
示例9: openPDF
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def openPDF(path, data):
return
# def openCSV(path, data):
# path = input("\n\tEnter the name of the text and extension of the text, CSV, or PDF file (has to be in same directory) to be mass analyzed in Emote: ")
# try:
# with open(path) as csvfile:
# reader = csv.reader(csvfile, dialect='excel', quoting=csv.QUOTE_NONNUMERIC)
# datalist = []
# datalist = list(reader)
# return datalist
# except IOError as err:
# print("Error opening path to file.")
# startInterface()
# return
示例10: dump
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def dump(self):
"""
:param saveto:
:return:
"""
filePath = self.csvFilePath
isCsvExists = os.path.exists(filePath)
data = self.data
fields = self.fields
with open(filePath, 'a') as f:
wr = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
if not isCsvExists:
# 新文件,需要写入表头
wr.writerow(fields)
for d in data:
# 写入数据
wr.writerow(d.values())
示例11: d_to_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def d_to_csv(d, with_header=True, carriage_return=True):
df = []
results = d["results"]
if results:
header = sorted(results[0].keys())
if with_header:
df.append(["query"] + header)
for res in results:
row = [d["query"]]
for key in header:
row.append(res[key])
df.append(row)
output = io.StringIO()
writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC)
for row in df:
writer.writerow(row)
csv_string = output.getvalue()
if carriage_return:
return csv_string
else:
return csv_string[:-1]
示例12: save_csv
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def save_csv (prefix='data'):
# Dump the ChangeSets
if len(ChangeSets) > 0:
fd = open('%s-changesets.csv' % prefix, 'w')
writer = csv.writer (fd, quoting=csv.QUOTE_NONNUMERIC)
writer.writerow (['Commit', 'Date', 'Domain',
'Email', 'Name', 'Affliation',
'Added', 'Removed'])
for commit in ChangeSets:
writer.writerow(commit)
# Dump the file types
if len(FileTypes) > 0:
fd = open('%s-filetypes.csv' % prefix, 'w')
writer = csv.writer (fd, quoting=csv.QUOTE_NONNUMERIC)
writer.writerow (['Commit', 'Type', 'Added', 'Removed'])
for commit in FileTypes:
writer.writerow(commit)
示例13: get_csv_stats
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def get_csv_stats(stats, recorded_cols=None):
"""
Create a CSV buffer from the stats DataFrame.
Parameters
----------
path: str
stats: list[Object]
recorded_cols: list[str]
Returns
-------
"""
df, columns = prepare_stats(stats, recorded_cols=recorded_cols)
return df.to_csv(
None,
columns=columns,
# encoding='utf-8',
quoting=csv.QUOTE_NONNUMERIC
).encode()
示例14: update_subjects_context_open_context_db
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def update_subjects_context_open_context_db(
project_uuid=PROJECT_UUID,
source_prefix=SOURCE_ID_PREFIX,
load_files=DESTINATION_PATH,
all_contexts_file=FILENAME_ALL_CONTEXTS,
loaded_contexts_file=FILENAME_LOADED_CONTEXTS,
):
"""Loads subjects, contexts items and containment relations"""
all_contexts_df = pd.read_csv((load_files + all_contexts_file))
new_contexts_df = update_contexts_subjects(
project_uuid,
(source_prefix + all_contexts_file),
all_contexts_df
)
loaded_contexts_path = (load_files + loaded_contexts_file)
new_contexts_df.to_csv(
loaded_contexts_path,
index=False,
quoting=csv.QUOTE_NONNUMERIC
)
示例15: update_link_rel_open_context_db
# 需要导入模块: import csv [as 别名]
# 或者: from csv import QUOTE_NONNUMERIC [as 别名]
def update_link_rel_open_context_db(
project_uuid=PROJECT_UUID,
source_prefix=SOURCE_ID_PREFIX,
load_files=DESTINATION_PATH,
link_sources=LINK_RELATIONS_SOURCES,
loaded_link_file_prefix='loaded--',
):
"""Loads linking relationships into the database"""
for source_id, filename in link_sources:
df = pd.read_csv((load_files + filename))
df = load_link_relations_df_into_oc(
project_uuid,
source_id,
df
)
df.to_csv(
(load_files + loaded_link_file_prefix + filename),
index=False,
quoting=csv.QUOTE_NONNUMERIC
)