篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 数据集 - mainupulacao de arquivo相关的知识,希望对你有一定的参考价值。
#cria um dataset
dataset = {'Actor': [],
'Total Gross': [],
'Number of Movies': [],
'Average per Movie': [],
'#1 Movie': [],
'Gross': []}"
#manipulacao com dataset - CSV
with open('actors.csv', 'r') as f:
arquivo_csv = csv.reader(f, delimiter=',', quotechar='"')
for i, row in enumerate(arquivo_csv):
# pulando o header
if i == 0:
continue
# parsing
dataset['Actor'].append(row[0])
dataset['Total Gross'].append(float(row[1]))
dataset['Number of Movies'].append(int(row[2]))
dataset['Average per Movie'].append(float(row[3]))
dataset['#1 Movie'].append(row[4])
dataset['Gross'].append(float(row[5]))
#manipulacao com arquivo texto
#linha a linha
f = open("demofile.txt", "r")
for x in f:
print(x)
#arquivo inteiro
f = open("demofile.txt", "r")
print(f.read())
#ver DictReader
dataset = {}
with open('googleplaystore.csv', 'r') as f:
arquivo_csv = csv.reader(f, delimiter=',', quotechar='"')
for i, row in enumerate(arquivo_csv):
if i ==0:
header = row
print(header)
for col_name in header:
dataset[col_name] = []
continue
if len(row) != len(header):
print('Skipping row with missing values...')
continue
for j, item in enumerate(row):
col_name = header[j]
if col_name == 'Installs':
item = float(item.replace('+', '').replace(',', ''))
if col_name == 'Price':
item = float(item.replace('$', ''))
dataset[col_name].append(item)
以上是关于text 数据集 - mainupulacao de arquivo的主要内容,如果未能解决你的问题,请参考以下文章