CSV to Markdown Table Shortcut

Just in case anyone else may find this useful, I made a Shortcut that converts a CSV file into a Markdown Table. Tested it on a CSV file containing 5 columns and over 700 rows and its works beautifully :+1:

https://www.icloud.com/shortcuts/994010aa0fe64b5a99b77992728cea52

3 Likes

Note: my mdpre project also does this - but you bracket it with =csv and =endcsv - generally as part of a bigger file. The idea is to prepare for conversion to PowerPoint (with md2pptx).

I realize it’s an extreme case, but this shortcut becomes unresponsive (spinning beachball) when processing my CSV list of 28k cities’ geolocation. 28,101 lines in the following fashion:

50.766602,6.0999999,Aachen,Germany
40.900946,-77.453383,Aaronsburg,PA
18.284841,-67.140978,Aasco,PR
5.0999999,7.3499999,Aba,Nigeria

1 Like

You aren’t alone… I have run into the same thing. The Shortcuts app in general seems to have trouble processing larger amounts of data. Even with a CSV containing “only” 700 plus rows it does occasionally freeze on me temporarily, unfreezes, and then successfully runs the Shortcut. :rofl::man_facepalming::man_shrugging:

Hello there.

I’ve worked with large CSV in Shortcuts before and the comments about unresponsiveness caught my attention.

While “Split Text” and “Repeat with Each” are pretty intuitive and really useful, they are very inefficient when working with lots of data. If you are comfortable with regular expressions you can go much faster (sometimes it feels like a superpower! :grin:). For example, this is my optimized version of the shortcut above:

https://www.icloud.com/shortcuts/f6874826748449ac8e1b6cf229414e54

I’ve only modified the CSV conversion to Markdown part (I haven’t touched the shortcut below the “Combine Text” action) and, other than achieving the same results without using “Split Text” and “Repeat with Each”, I’ve added a question about the CSV having a header line or not.

These are the results of CSV to Markdown Table in my iPad Pro 12.9" M2:

Original (1% of data): 4.2 seconds
Original (3% of data): 16.3 seconds
Original (5% of data): CRASH
Original (10% of data): CRASH
Original (100% of data): CRASH

Optimized (1% of data): 0.1 seconds
Optimized (3% of data): 0.1 seconds
Optimized (5% of data): 0.2 seconds
Optimized (10% of data): 0.3 seconds
Optimized (100% of data): 1.7 seconds

And these are the results in my Mac Mini M1:

Original (1% of data): 1.7 seconds
Original (3% of data): 6.5 seconds
Original (5% of data): CRASH
Original (10% of data): CRASH
Original (100% of data): CRASH

Optimized (1% of data): 0.1 seconds
Optimized (3% of data): 0.1 seconds
Optimized (5% of data): 0.2 seconds
Optimized (10% of data): 0.3 seconds
Optimized (100% of data): 1.9 seconds

The data mentioned is the free dataset from World Cities Database | Simplemaps.com (44k rows, 11 columns)

The partial datasets used are from the beginning of the CSV in the link below but they’re also at https://www.atnbueno.com/automators/worldcities_partial_datasets.zip

P.S. I forgot: this is the original shortcut with the time measure added
https://www.icloud.com/shortcuts/4a405b74eb1541d1b7998c1b28b45fbd

2 Likes

This is amazing!! Thank you thank you thank you!!! :drooling_face::grin::+1:

1 Like