0
def general_number(request):
    csvfilename = 'algo/generalnumber.csv'
    csvfile = open(csvfilename, 'r')
    reader = csv.DictReader(csvfile)
    fieldnames = ("Ticker","Company","Industry","PreviousClose","Open","Bid","Ask","DaysRange","ftWeekRange","Volume","AvgVolume","MarketCap","Beta","PERatioTTM","EPSTTM","EarningsDate","ForwardDividendYield","ExDividendDate","OneyTargetEst","ticker_company")
    output = []
    for each in reader:
      row = {}
      for field in fieldnames:
        row[field] = each[field]
        output.append(row)
    return JsonResponse(output[20:30],safe=False)

Here I am getting duplicate data in json from csv. Each datum is showing 10 times. What is wrong in this?

2
  • 1
    De-indent output.append(row) by two spaces Commented Oct 1, 2018 at 16:44
  • no. here it will give error if i will put indentation afetr row[field] Commented Oct 1, 2018 at 16:45

1 Answer 1

1

It's just an indentation problem. Fixed it, try now!

def general_number(request):
    csvfilename = 'algo/generalnumber.csv'
    csvfile = open(csvfilename, 'r')
    reader = csv.DictReader(csvfile)
    fieldnames = ("Ticker","Company","Industry","PreviousClose","Open","Bid","Ask","DaysRange","ftWeekRange","Volume","AvgVolume","MarketCap","Beta","PERatioTTM","EPSTTM","EarningsDate","ForwardDividendYield","ExDividendDate","OneyTargetEst","ticker_company")
    output = []
    for each in reader:
      row = {}
      for field in fieldnames:
        row[field] = each[field]
      output.append(row)
    return JsonResponse(output[20:30],safe=False)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.