Read plain text file data from csv map
Project description
readPos Package usage
readPos is a package built to work with data files by positions. So we gonna need some text plain data file and some definition files (csv) to read that data.
With some methods we can directly work with dataframe objetc (pandas) and a definition file to construct the dat file output.
IMPORT PACKAGE IN OUT SCRIPTS
The statement to import some objects and methos from readPos Package is like this:
from readPos.readPos import {{METHOD}}
Where {{METHOD}} we must indicate which object we gonna import. The most used is:
from readPos.readPos import ReadPos
ReadPos class need two params to create an instance:
-
file_name = this param will be a string containing the absolute or relative path to data file we wanna work with (if we gonna write some dat file, this gonna be the output name)
-
csv_file = this param will be a string containing the absolute or relative path to csv file that contains the definition for each variable we wanna work with. This file must contain 3 fields at least (order not matter but exact column name does):
- variable: string field that have a value (without spaces and non number starting) used to set column names in read method or to match dataframe columns in write method.
- initial: integer field. Initial position (not index) where data will be read from input file or where will be writted in output file.
- end: integer field. Final position (not index) where data will be read from input file or where will be writted in output file.
Other self information columns (descriptions, length) can be added to csv file, them not gonna do a crash error but can overcharge process time. Initial position of the variables could not be in ascending order. The read/write method will order it internally.
HOW TO READ DAT FILES INTO STRUCTURED DATA FRAME
from readPos.readPos import ReadPos
readpos_instance = ReadPos(file_name = 'C:/Users/MyUser/dummy.dat', csv_file = 'definition.csv')
dataframe = readpos_instance.read() # dataframe objetct will be a pandas core dataframe with as many columns as rows you have in your csv file and as many rows as lines you have in your
Optional "encoding" param with string like 'latin-1' is allowed. Default value = 'UTF-8'
HOW TO ERITE DAT FILES FROM STRUCTURED DATA FRAME
from readPos.readPos import ReadPos
readpos_instance = ReadPos(file_name = 'C:/Users/MyUser/dummy.dat', csv_file = 'definition.csv')
readpos_instance.write(df) # df is a dataframe object with at least all de columns that we have defined in csv file. df can contain more columns than csv, so these columns will be not written in output dat file.
*Optional "encoding" param with string like 'latin-1' is allowed. Default value = 'UTF-8'*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file readPos-0.2.tar.gz.
File metadata
- Download URL: readPos-0.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d96aa92dedb3cbef957e0ac43f622c83a2e1cb18373a6aad3cd5d566768a4a9
|
|
| MD5 |
d0ffa35d18d9d4af16ad0428dec0670f
|
|
| BLAKE2b-256 |
0a327a2429c6e019f21db67244f620dd64a787ee1e267e3995f99397fbbf4322
|