Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the way to output/generate the csv file #19

Open
dadiorchen opened this issue Dec 20, 2021 · 2 comments
Open

Improve the way to output/generate the csv file #19

dadiorchen opened this issue Dec 20, 2021 · 2 comments
Labels
csv good first issue Good for newcomers

Comments

@dadiorchen
Copy link
Contributor

Now we just simply write csv with join, we need to improve the output in a professional way like using csv lib to do it.

sql = f"SELECT {','.join(columns)} FROM trees LIMIT 20"
print("SQL:", sql)
# execute query
cur.execute(sql)
# fetch all rows
rows = cur.fetchall()
lines = [','.join(columns)]
# print rows
print ("rows:", rows)
for row in rows:
print ("row:", row)
# join row elements with comma
line = ",".join(str(v) for v in row)
# add line to lines
lines.append(line)
print ("lines:", lines)
print ("lines length:", len(lines))

@dadiorchen dadiorchen added good first issue Good for newcomers csv labels Dec 20, 2021
@dark-teal-coder
Copy link
Member

Do I have to understand your entire script? After I ran it, there's no output on my screen.

@vishanthan8055
Copy link

dframe = pd.read_csv(‘file_name.csv’,nrows=number)

This is the best way to print the csv with with n number of rows and we can export through many modules and functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csv good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants