In [26]:
import pandas as pd
import numpy as np
from os import listdir
from os.path import isfile, join

In [27]:
#files = ["overview", "transfer_of_resources_to_states", "social_sector_allocations_and_priorities","tax_gdp_buoyancy", "annual_estimated_revenue_foregone", "price_rise", "education", "health", "drinking_water_and_sanitation", "ministry_of_rural_development", "agriculture", "food_security","nutrition", "climate_change", "women", "children", "dalits", "adivasis", "religious_minorities", "social_security", "urban_poverty", "disability", "share_of_expenditure_by_moa", "share_of_food_subsidy_allocation"]
path= "data/"
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]


Traceback (most recent call last):
  File "/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.py", line 970, in get_records
    return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
  File "/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.py", line 233, in wrapped
    return f(*args, **kwargs)
  File "/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.py", line 267, in _fixed_getinnerframes
    records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/home/akshay/anaconda2/lib/python2.7/inspect.py", line 1049, in getinnerframes
    framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File "/home/akshay/anaconda2/lib/python2.7/inspect.py", line 1009, in getframeinfo
    filename = getsourcefile(frame) or getfile(frame)
  File "/home/akshay/anaconda2/lib/python2.7/inspect.py", line 454, in getsourcefile
    if hasattr(getmodule(object, filename), '__loader__'):
  File "/home/akshay/anaconda2/lib/python2.7/inspect.py", line 483, in getmodule
    file = getabsfile(object, _filename)
  File "/home/akshay/anaconda2/lib/python2.7/inspect.py", line 467, in getabsfile
    return os.path.normcase(os.path.abspath(_filename))
  File "/home/akshay/anaconda2/lib/python2.7/posixpath.py", line 364, in abspath
    cwd = os.getcwd()
OSError: [Errno 2] No such file or directory
ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.


Unfortunately, your original traceback can not be constructed.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_code(self, code_obj, result)
   3081             if result is not None:
   3082                 result.error_in_exec = sys.exc_info()[1]
-> 3083             self.showtraceback()
   3084         else:
   3085             outflag = 0

/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in showtraceback(self, exc_tuple, filename, tb_offset, exception_only)
   1878                     except Exception:
   1879                         stb = self.InteractiveTB.structured_traceback(etype,
-> 1880                                             value, tb, tb_offset=tb_offset)
   1881 
   1882                     self._showtraceback(etype, value, stb)

/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1240         self.tb = tb
   1241         return FormattedTB.structured_traceback(
-> 1242             self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1243 
   1244 

/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1148             # Verbose modes need a full traceback
   1149             return VerboseTB.structured_traceback(
-> 1150                 self, etype, value, tb, tb_offset, number_of_lines_of_context
   1151             )
   1152         else:

/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1000 
   1001         formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
-> 1002                                                                tb_offset)
   1003 
   1004         colors = self.Colors  # just a shorthand + quicker name lookup

/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.pyc in format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)
    949         records = self.get_records(etb, number_of_lines_of_context, tb_offset)
    950 
--> 951         frames = self.format_records(records)
    952         if records is None:
    953             return ""

/home/akshay/anaconda2/lib/python2.7/site-packages/IPython/core/ultratb.pyc in format_records(self, records)
    722 
    723         abspath = os.path.abspath
--> 724         for frame, file, lnum, func, lines, index in records:
    725             #print '*** record:',file,lnum,func,lines,index  # dbg
    726             if not file:

TypeError: 'NoneType' object is not iterable

In [8]:
def add_slug(path):
    df=pd.read_csv(path)
    df["slug_name"] = np.nan
    for index, row in enumerate(df.iterrows()):
        row[1][-1] = "_".join(row[1][0].split(" ")).lower()
        df["slug_name"][index] = "_".join(row[1][-1].split(" ")).lower()
        cols = df.columns.tolist()
    cols = cols[-1:] + cols[:-1]
    df = df[cols]
    df.to_csv(path, index=False)

In [11]:
add_slug("data/compo_misc_capital_recipts.csv")


/home/akshay/anaconda2/lib/python2.7/site-packages/ipykernel/__main__.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [19]:
for fil in onlyfiles:
    #path = "data/"+fil+".csv"
    print fil
    #try :
    if fil[0] != "." and fil != "table_list.csv" :
        add_slug(path+fil)
    #add_slug(path)
    #except :
    #    print fil


climate_change.csv
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-417349ab54b7> in <module>()
      4     #try :
      5     if fil[0] != "." and fil != "table_list.csv" :
----> 6         add_slug(path+fil)
      7     #add_slug(path)
      8     #except :

<ipython-input-17-fed9d166397c> in add_slug(path)
      4     df["slug_name"] = np.nan
      5     for index, row in enumerate(df.iterrows()):
----> 6         row[1][-1] = "_".join(row[1][0].split(" ")).lower()
      7         df["slug_name"][index] = "_".join(row[1][-1].split(" ")).lower()
      8         cols = df.columns.tolist()

AttributeError: 'float' object has no attribute 'split'

In [ ]: