<commit_before># -*- coding: utf-8 -*-
"""
Created on Tue May  6 15:13:59 2014

@author: pacificoadrien
"""

from sas7bdat import SAS7BDAT
import pandas as pd
import os
import sys



def extract_from_sas(file_to_import):
    f = SAS7BDAT(file_to_import)
    outFile = ("/Users/pacificoadrien/Downloads/help.csv")


    def convertFile(sas7bdat, outFile, delimiter=',', stepSize=100000):
            try:
                if outFile == '-':
                    outF = sys.stdout
                else:
                    outF = open(outFile, 'w')
                    df = pd.DataFrame()

                i = 0
                for i, line in enumerate(sas7bdat.readData(), 1):
                    if not line:
                        i -= 1
                        continue

                    if not i % stepSize:
                        sas7bdat.logger.info('%.1f%% complete',
                                         float(i) / sas7bdat.header.rowcount * 100.0)
                    try:
#                        print(i)
                        if i == 1:

                            df = pd.DataFrame( columns= line )
                        else:
                         df = df.append( dict(zip(df.columns,line)), ignore_index = True)

                    except IOError:
                        sas7bdat.logger.warn('Wrote %d lines before interruption', i)
                        break
                sas7bdat.logger.info('[%s] wrote %d of %d lines',
                                 os.path.basename(outFile), i - 1,
                                 sas7bdat.header.rowcount)
            finally:
                print(df)
                if outF is not None:
                    outF.close()


    convertFile(f, outFile, delimiter=',', stepSize=100000)




if __name__ == '__main__':
    extract_from_sas("/Users/pacificoadrien/Downloads/help.sas7bdat")
<commit_msg>find the location of the exemple sas7bdat file<commit_after># -*- coding: utf-8 -*-
"""
Created on Tue May  6 15:13:59 2014

@author: pacificoadrien
"""

from sas7bdat import SAS7BDAT
import pandas as pd
import os
import sys



def extract_from_sas(file_to_import):
    f = SAS7BDAT(file_to_import)
    outFile = ("/Users/pacificoadrien/Downloads/help.csv")


    def convertFile(sas7bdat, outFile, delimiter=',', stepSize=100000):
            try:
                if outFile == '-':
                    outF = sys.stdout
                else:
                    outF = open(outFile, 'w')
                    df = pd.DataFrame()

                i = 0
                for i, line in enumerate(sas7bdat.readData(), 1):
                    if not line:
                        i -= 1
                        continue

                    if not i % stepSize:
                        sas7bdat.logger.info('%.1f%% complete',
                                         float(i) / sas7bdat.header.rowcount * 100.0)
                    try:
#                        print(i)
                        if i == 1:

                            df = pd.DataFrame( columns= line )
                        else:
                         df = df.append( dict(zip(df.columns,line)), ignore_index = True)

                    except IOError:
                        sas7bdat.logger.warn('Wrote %d lines before interruption', i)
                        break
                sas7bdat.logger.info('[%s] wrote %d of %d lines',
                                 os.path.basename(outFile), i - 1,
                                 sas7bdat.header.rowcount)
            finally:
                print(df)
                if outF is not None:
                    outF.close()


    convertFile(f, outFile, delimiter=',', stepSize=100000)




if __name__ == '__main__':

    import pkg_resources
    openfisca_france_location = pkg_resources.get_distribution('openfisca-france-data').location
    file_exemple_location = openfisca_france_location + "/openfisca_france_data/scripts/help.sas7bdat"
    extract_from_sas(file_exemple_location)
{'fraction_non_alphanumeric': 0.09628886659979939, 'fraction_numerical': 0.022818455366098295, 'mean_word_length': 1.2549462973431318, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3389837', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1097, 'n_words': 252}