Posts

Showing posts with the label read

csv to list in python

This is dead simple way to read a csv file and feed the data into a Python list: import csv with open('file.csv', 'rb') as f:     reader = csv.reader(f)     your_list = list(reader) print your_list # [['This is the first line', 'Line1'], # ['This is the second line', 'Line2'], # ['This is the third line', 'Line3']] Reference:   http://stackoverflow.com/questions/24662571/python-import-csv-to-list

Generating Google Form from Google Spreadsheet using Google Apps Script

Google Form is such a great tool for us to create surveys with a great web interface. But, the thing is even with the cool drag-and-drop features, It's still a pain in the ass to generate forms from a mass amount of data (questions and choices). That's where Google Apps Scripts comes into its usefulness. Here is a case study from my real life experience: Earlier this week I had a chance to tinkering around the apps scripts to help my school create a survey with a set of data stored inside an excel file. The final goal is to create a form in which students give feedback to each of their teachers on each courses. So the excel data looks like this: Teachers sheet: this sheet contains 3 columns, each column is a list of all the teachers of each schools (elementary, middleschool and highschool) es,ms,hs teacher1,teacher2,teacher3 teacher6,teacher7,teacher8 ... Courses sheet: the courses sheets is storing name of the courses each teacher is teaching teacher1,teacher2,t...

Transposing csv data using Python

Here is the case: You have this original csv data: name,course,number A,Genius,12 A,Super,13 B,Goddess,15 C,The Man,17 C,The Woman,10 C,Harvard,11 C,StanFord,18 and you want to create another csv file that uses name 's values as columns and group the course 's value as rows: A,B,C Genius,Goddess,The Man Super,'',The Woman '','',Harvard '','',StanFord Here is what I did to achieve that: 1. Read the original csv file and convert it into a list of dicts 2. Transpose the list by grouping the name column: Get all the name's value group_cols = [] for o in original_list: if o[group_col_name].strip() not in group_cols: group_cols.append(o[group_col_name].strip()) For each of the name, loop through the original list and append the according course's value to a tmp list (with the name as the first item), then add all of the tmp lists to a new list: thelist = [] for c in group_co...

Becoming Steve Jobs

Image
The first time I heard of this book I was like "Oh my, another Steve's book?". But, I gave it a try and found out a lot of interesting things about Steve Jobs's life. He's not a saint, not a pure genius, but a continuous autopilot, a reckless individual grown into a extraordinary leader that would led his company to great success and changed the world. I don't want to tell more about "Becoming Steve Jobs". You have to read this book and learn! Here are some photos from the book:

CSV file to PHP array

Here is a pretty cool snippet to read csv file and turn it into a php array: function read_csv($csv_path){ $file = fopen($csv_path, 'r'); while (!feof($file) ) { $lines[] = fgetcsv($file); } fclose($file); return $lines; }

Articles of the week

These are articles I read this week which were great: The importance of a good night's sleep : http://www.historytoday.com/katharine-craik/importance-good-nights-sleep Katharine A. Craik explains the importance of sleep to the human being and what kind of factors that affect our sleep. Tired of recruiting's broken image, AirBnB rewrites the playbook : http://www.forbes.com/sites/georgeanders/2015/05/06/airbnbs-5-star-recruiting-twist-the-competitive-power-of-nice/ The article started with the story of Joe Gebbia, AirBnB founder, a graphic designer who couldn't get a job.

Quote of the day

"Everybody wants a good life, but not everybody willing to read to get it." ~Tai Lopez.

To Read Is To Fly

Image
Here are some great resources for readers or book lovers like me to read online: The Public Domain Review : http://publicdomainreview.org/ " The Public Domain Review is a not-for-profit project dedicated to showcasing the most interesting and unusual out-of-copyright works available online. All works eventually fall out of copyright – from classic works of art, music and literature, to abandoned drafts, tentative plans, and overlooked fragments. In doing so they enter the public domain, a vast commons of material that everyone is free to enjoy, share and build upon without restriction. We believe the public domain is an invaluable and indispensable good, which – like our natural environment and our physical heritage – deserves to be explicitly recognised, protected and appreciated. The Public Domain Review aims to help its readers to explore this rich terrain – like a small exhibition gallery at the entrance of an immense network of archives and storage rooms that lie...