Category;currency;sellerRating;Duration;endDay;ClosePrice;OpenPrice;Competitive?
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Music/Movie/Game;US;3249;5;Mon;0,01;0,01;No
Automotive;US;3115;7;Tue;0,01;0,01;No
Automotive;US;3115;7;Tue;0,01;0,01;No
Automotive;US;3115;7;Tue;0,01;0,01;Yes
There is in the actual file no whitspaces, but otherwise it would display wrong. I want to calculate the standard dividation from each categorie.
I tried to use this: statistics.stdev() but that does not work. Can anyone help me and when you have the awnser can you explain it so I can learn.
from csv import DictReader
from collections import defaultdict
from statistics import median
from locale import setlocale
from locale import LC_ALL
from locale import atof
setlocale(LC_ALL, 'Dutch_Netherlands.1252')
median_names = 'sellerRating', 'Duration', 'ClosePrice', 'OpenPrice'
print ("Mediaan : ")
data = defaultdict(list)
with open('bijlage.txt') as f:
csvreader = DictReader(f, delimiter=';')
for dic in csvreader:
for header, value in dic.items():
data[header].append(value)
for median_name in median_names:
med = median(map(atof, data[median_name]))
print('{:<13} {:>10}'.format(median_name, med))
from collections import defaultdict
import csv
import locale
import statistics
from pprint import pprint, pformat
import locale
locale.setlocale(locale.LC_ALL, 'Dutch_Netherlands.1252')
avg_names = 'sellerRating', 'Duration', 'ClosePrice', 'OpenPrice'
averages = {avg_name: 0 for avg_name in avg_names}
seller_ratings = defaultdict(list)
num_values = 0
with open('bijlage.txt', newline='') as bestand:
csvreader = csv.DictReader(bestand, delimiter=';')
for row in csvreader:
num_values += 1
for avg_name in avg_names:
averages[avg_name] += locale.atof(row[avg_name])
seller_ratings[row['Category']].append(locale.atof(row['sellerRating']))
for avg_name, total in averages.items():
averages[avg_name] = total / num_values
print()
print('Averages:')
for avg_name in avg_names:
rounded = locale.format_string('%.2f', round(averages[avg_name], 2),
grouping=True)
print(' {:<13} {:>10}'.format(avg_name, rounded))
modes = {}
for category, values in seller_ratings.items():
try:
modes[category] = statistics.mode(values)
except statistics.StatisticsError:
modes[category] = None # No unique mode.
print()
print('Modes:')
for category, mode in modes.items():
if mode is None:
print(' {:<20} {:>10}'.format(category, '-'))
else:
rounded = locale.format_string('%.2f', round(mode, 2), grouping=True)
print(' {:<20} {:>10}'.format(category, rounded))