Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to Get My Data of Output File Sorted in Python Program?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 483
    Answer it

    I want writing function for sorted_average() .  I calculated average of data in input file and write them in my output file. then i want sort data of out put file. but my cod not working...


    my out put file is : 

    • mandana,7.5
    • hamid,6.066666666666666
    • sina,11.285714285714286
    • sara,9.75
    • soheila,7.833333333333333
    • ali,5.0
    • sarvin,11.375


    I want sorting this numbers....can help me?


    def calculate_sorted_averages(input_file_name, output_file_name):
        labels = ['name', 'mean_grade']
        with open(input_file_name, 'r') as file_obj:
            csv_obj = csv.reader(file_obj)
            data = [
                [row[0], statistics.mean(float(grade) for grade in row[1:])]
                for row in csv_obj]
            # sort data according to `name`
        sorted(data, key=lambda x: x[0])
        with open(output_file_name, 'w') as file_obj:
                obj = csv.writer(file_obj)
                for row in data:
        return file_obj


 0 Answer(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: