Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.79 KB

2014-07-06-my-csv-python-video-gets-10000-views.md

File metadata and controls

48 lines (33 loc) · 1.79 KB
layout title categories tags comments
post
My CSV python video gets 10000 views
code
code
python
csv
true

So the other day I got the following notification on my phone:

This both terrified me and made me smile. It's nice to think that a bunch of people have (hopefully) been helped with what I put together but also slightly worrying as I think I would be able to put together a much better video if I did it now.

Here it is:

<iframe width="560" height="315" src="//www.youtube.com/embed/jQ9aDyBWCXI" frameborder="0" allowfullscreen></iframe>

The basic code I use in the video is:

{% highlight python %} import csv

out = open('data.csv', 'r') # Open a file in read mode data = csv.reader(out) # Initiate a csv reader object which will parse the data data = [[row[0], eval(row[1]), eval(row[2])] for row in data] # Read in the data and convert certain entries of each row out.close() # Close the file

new_data = [[row[0], row[1] + row[2]] for row in data] # Create some new data

out = open('new_data.csv', 'w') # Open a file in write mode output = csv.writer(out) # Initiate a csv writer object which will write the data in the correct format (csv)

for row in new_data: # Loop through the data output.writerow(row) # Write the row to file

out.close() # Close the file {% endhighlight %}

There are a couple of other videos that are getting near that landmark, this is possibly my favourite of them:

<iframe width="560" height="315" src="//www.youtube.com/embed/WEA8m3j-Jqk" frameborder="0" allowfullscreen></iframe>

The above video shows how to simulate a basic queue in Python. My Summer student James Campbell and I are working on something related at the moment.