How can I load the data from a csv file, rather than being typed into my python program -


i take these inputs loaded csv file. not typed python code. changes should make? created csv file. have problem importing data in python-code.

the source code link https://github.com/joelgrus/data-science-from-scratch/blob/master/code/decision_trees.py

the inputs import csv file following:

inputs = [         ({'level':'senior','lang':'java','tweets':'no','phd':'no'},   false),         ({'level':'senior','lang':'java','tweets':'no','phd':'yes'},  false),         ({'level':'mid','lang':'python','tweets':'no','phd':'no'},     true),         ({'level':'junior','lang':'python','tweets':'no','phd':'no'},  true),         ({'level':'junior','lang':'r','tweets':'yes','phd':'no'},      true),         ({'level':'junior','lang':'r','tweets':'yes','phd':'yes'},    false),         ({'level':'mid','lang':'r','tweets':'yes','phd':'yes'},        true),         ({'level':'senior','lang':'python','tweets':'no','phd':'no'}, false),         ({'level':'senior','lang':'r','tweets':'yes','phd':'no'},      true),         ({'level':'junior','lang':'python','tweets':'yes','phd':'no'}, true),         ({'level':'senior','lang':'python','tweets':'yes','phd':'yes'},true),         ({'level':'mid','lang':'python','tweets':'no','phd':'yes'},    true),         ({'level':'mid','lang':'java','tweets':'yes','phd':'no'},      true),         ({'level':'junior','lang':'python','tweets':'no','phd':'yes'},false)     ] 

i imported them hand. (i created csv, writing data , import them script). aim export csv file , import automatically values script.

if csv file formatted as

level,lang,tweets,phd senior,java,no,no ................ 

you can use

csvfile=open('your_csv_file.csv',encoding="utf8") csvreader = csv.dictreader(csvfile) record in csvreader:     #do watever want 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -