1
import sqlite3
import csv

conn=sqlite3.connect("D:/asdfef.xdb")

cur=conn.cursor()

cur.execute("select max(ue_rsrp) from  lte_ue_rf") #sql query to calculate the avergae

rows = cur.fetchall() 

columns = [i[0] for i in cur.description]

with open("D:/asdf.csv",'w') as file:
   writer=csv.writer(file)
   writer.writerow(columns)
   writer.writerow(rows)

Above is the code used to retrieve the avg of an item in the DB, but my output shows up as a list (-79.25,). Why is this happening and what should be done to rectify this. I am a beginner with python coding

3
  • 1
    Hi Sarith, Can you please provide the sample data from table, as the query is simply fetching the max value from table. Commented Nov 28, 2018 at 10:26
  • RI UE_RSRP 1 -102 2 -86 3 -97 4 -76.2 5 -75.4 Commented Nov 28, 2018 at 11:56
  • Did you mean avg instead of max in code? Do you get one-element list or is there something else? See also this question Commented Nov 30, 2018 at 11:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.