troubleshooting Question

save dataframe to a csv file in python

Avatar of ocean O
ocean O asked on
Python
7 Comments1 Solution32 ViewsLast Modified:
Hi, I have a question for python.  I had use cursor.fetchmany() to fetch the data. It will fetch multiple times depends on the data number. I want to generate one csv file after all the fetching. How can I do it? Code is below. Thanks

 datafile = pd.DataFrame([])
       
            while True:

                results = cursor.fetchmany(7000)

                if not results:
                    break
               

                col_Names = ['market', 'site_id', 'latitude', 'longitude', 'state', 'zip', 'structure_type']
                data = pd.DataFrame(results)
                data.to_csv(filename, index=False, header=col_Names) //This is the first time fetching
          //how can I append the next fetching data to the csv file?
               

        cursor.close()
ASKER CERTIFIED SOLUTION
Louis LIETAER
System Infrastructure Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros