abstract_data_project.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:the-magical-csv-merge-machine 作者: entrepreneur-interet-general 项目源码 文件源码
def to_xls(self, module_name, file_name):
        '''
        Takes the file specified by module and file names and writes an xls in 
        the same directory with the same name (changing the file extension).

        Columns of the original file will be written in the first sheet.
        Columns containing "__" will be written the second sheet

        Use for download only!

        INPUT:
            - module_name:
            - file_name:
        '''
        raise DeprecationWarning('Excel download currently not supported due'\
                                 'to potential memory issues with large files')

        file_path = self.path_to(module_name, file_name)

        assert file_name[-4:] == '.csv'
        new_file_name = file_name[:-4] + '.xlsx'
        new_file_path = self.path_to(module_name, new_file_name)

        tab = pd.read_csv(file_path, encoding='utf-8', dtype=str)


        columns_og = [x for x in tab.columns if '__' not in x]
        columns_new = [x for x in tab.columns if '__' in x]

        writer = pd.ExcelWriter(new_file_path)
        tab[columns_og].to_excel(writer, 'original_file', index=False)
        tab[columns_new].to_excel(writer, 'normalization', index=False)
        writer.save()        
        return new_file_name
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号