DEV Community

Cover image for From TSV to CSV: How GitHub Copilot Chat Made Data Conversion a Breeze!
Kedasha for GitHub

Posted on

From TSV to CSV: How GitHub Copilot Chat Made Data Conversion a Breeze!

I recently discovered that GitHub projects has TSV exports! πŸ’ƒπŸΌ

projects-export-tsv

I was super excited about this but it also made me realize that some folks may want/prefer csv files and so, I asked by bestie - GitHub Copilot Chat - to help me convert a TSV file to a CSV file in Python.
Now, I'm not a Python Developer, so I wasn't sure how I would do this in Python, and while I could use an npm module like PapaParse to accomplish this, I wanted to try another language.

Honestly, it was pretty seamless!

Here's how I did it:

Step 1: Download your TSV file and add it to a folder, then open said folder in VSCode (or your preferred editor).

Step 2: Create a new Python file, I called mine tsv_to_csv.py.

Step 3: Navigate to GitHub Copilot Chat and ask "how do I convert a tsv file to csv with python?"
I was provided with the following code:



import csv

with open('ruby-study-guide.tsv', 'r') as tsvfile:
    reader = csv.reader(tsvfile, delimiter='\t')
    with open('ruby-study-guide.csv', 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)
        for row in reader:
            writer.writerow(row)
    print("Conversion complete!")


Enter fullscreen mode Exit fullscreen mode

If you're not familiar with GitHub Copilot Chat, read this blog post to learn how to get started with it.

Step 4: Paste the code into your file by clicking the "Insert at Cursor" icon.
insert at cursor icon GitHub Copilot Chat interface

Step 5: Save your file, run the code with python <<name of your file here>>, for example python tsv_to_csv.py, and enjoy your csv file!

Here's a video/gif on the steps I did above:

convert tsv to csv with Github copilot chat


Now that you know that GitHub Projects has TSV exports, learn more tidbits that you possibly didn't know by reading this blog post I wrote on 10 things you didn't know you could do with GitHub Projects.

Let me know if you have any questions about GitHub Copilot or GitHub Projects below!

Top comments (3)

Collapse
 
cicirello profile image
Vincent A. Cicirello

As you discovered with Copilot, Python's csv module is more versatile than just csv files, and can handle arbitrary delimiters.

One random DEV tip for you: DEV's editor supports syntax highlighting in code blocks. Here's how:

```Python
import csv

with open('ruby-study-guide.tsv', 'r') as tsvfile:
    reader = csv.reader(tsvfile, delimiter='\t')
```
Enter fullscreen mode Exit fullscreen mode

Produces:

import csv

with open('ruby-study-guide.tsv', 'r') as tsvfile:
    reader = csv.reader(tsvfile, delimiter='\t')
Enter fullscreen mode Exit fullscreen mode

It works for most languages. Just put language name after opening backticks.

Collapse
 
ladykerr profile image
Kedasha

Thank you! I'm not too familiar with Python so can't wait to. learn more about the csv module!

Also, Thanks so much for the tip! Updated! πŸ’ƒπŸΌ

Collapse
 
cicirello profile image
Vincent A. Cicirello

You're welcome. Python's a great language to learn. I use it a lot. It's not the language I use the most, but it's in my top 3.