Skip to content
Advertisement

Python – Write a row into an array into a text file

I have to work on a flat file (size > 500 Mo) and I need to create to split file on one criterion. My original file as this structure (simplified): JournalCode|JournalLib|EcritureNum|EcritureDate|CompteNum|

I need to create to file depending on the first digit from ‘CompteNum’.

I have started my code as well

JavaScript

It seems ok, my concern is to create my 2 files based on criteria. I have tried with unsuccess.

JavaScript

the result of my target file is not like I expected:

JavaScript

And I expected to obtain line into my target file when CompteNum(0:1) > 7

I have read many posts for 2 days, please some help will be perfect.

There is a sample of my data available here

Philippe

Advertisement

Answer

Suiting the rules and the desired format, you can use logic like:

JavaScript

Original comment:

As I understand it, you want to filter the imported dataframe according to some criteria. You can work directly on the pandas you imported. Look:

JavaScript

Once you have the filtered dataframes, you can save them or convert them to other objects, such as dictionaries.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement