Python Forum
Issue in writing sql data into csv for decimal value to scientific notation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue in writing sql data into csv for decimal value to scientific notation
#5
Hi Deanstyed,

great solution ,

but still unable to utilise correctly in my situation.

I dont want this ------>range(2, 14, 2)
I am ok for 0.0 value.


input data there are 300 columns to check , where is zero value
xyz 29-11-2022 0.0000000000 1.00002
abc 29-11-2022 0.000000000 200

expected output now
xyz | 29-11-2022| 0.0| 1.00002
abc | 29-11-2022| 0.0| 200



rows = [[Decimal(f'0E-{x}'), Decimal(f'1.2E-{x+1}')] for x in range(2, 14, 2)]

with open("test.csv", "w", newline="") as file:
writer = csv.writer(file, quoting=csv.QUOTE_NONE, delimiter="|")
for row in rows:
writer.writerow(map(lambda x: f'{x.normalize():f}', row))

#-----My Code----------

while True:
    rows = cursor.fetchmany(10000)
    if len(rows) == 0:
        print("no records found")
        break
    else:
        for row in rows:
            #writer.writerows(row)  instead of this line , # just to replace single line , I am writing more line
            for row in rows:
                    for x in row:
                           no = float(x)
                           if no ==0:
                               writer.writerows(row)
Reply


Messages In This Thread
RE: Issue in writing sql data into csv for decimal value to scientific notation - by mg24 - Nov-29-2022, 12:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 1,595 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  Forcing matplotlib to NOT use scientific notation when graphing sawtooth500 4 5,666 Mar-25-2024, 03:00 AM
Last Post: sawtooth500
  ''.join and start:stop:step notation for lists ringgeest11 2 4,098 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  issue with converting a scientific notation to standard notation thomaswfirth 4 3,271 Jun-06-2023, 06:06 PM
Last Post: rajeshgk
  notation MCL169 8 3,387 Apr-14-2023, 12:06 PM
Last Post: MCL169
  Create a function for writing to SQL data to csv mg24 4 2,715 Oct-01-2022, 04:30 AM
Last Post: mg24
  Issue in changing data format (2 bytes) into a 16 bit data. GiggsB 11 5,344 Jul-25-2022, 03:19 PM
Last Post: deanhystad
  Need Help writing data into Excel format ajitnayak87 8 4,300 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  Python issue - Data science - Help is needed yovel 2 2,900 Jul-29-2021, 04:27 PM
Last Post: yovel
  Fastest Way of Writing/Reading Data JamesA 1 3,055 Jul-27-2021, 03:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020