jeudi 7 juillet 2016

Use level of pandas index as a part of an output file name

I am trying to loop through a data frame using

for index, row in df.iterrows():
   #Do Stuff

I have a pandas data frame that looks like:

                  pt_ID Easting Northing         Attribute
Site  Survey_Date                                         
M006R 2004-12-30   1019  245473   651608  WE              
      2004-12-30   1038  245563   651543  WE              
      2004-12-30   1017  245471   651593  WE              
      2004-12-30   1021  245482   651616  WE              
      2004-12-30   1023  245478   651604  WE              
      2004-12-30   1049  245665   651498  WE              
      2004-12-30   1020  245477   651614  WE              
      2004-12-30   1041  245577   651528  WE              
      2004-12-30   1040  245574   651535  WE              
      2004-12-30   1037  245552   651544  WE   

As can bee seen I have a multindex using Site and Survey_Date. As It loops through the dataframe I would like to use the Survey_Date as a part of and output file name and have no idea how to access it as it loops through the data frame.

For example I would like an output filename of:

outfilename = 'test_' + Survey_Date + '.extention'

Is this possible?

Aucun commentaire:

Enregistrer un commentaire