Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

readPos-0.1.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

readPos-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file readPos-0.1.1.tar.gz.

File metadata

  • Download URL: readPos-0.1.1.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

Hashes for readPos-0.1.1.tar.gz
Algorithm Hash digest
SHA256 72c38cf29b95dd0f5f4109c72401de0e302491288a318b27fa7168eab57a6352
MD5 f144a546a38adb01bcdb3b4e80c478df
BLAKE2b-256 f3ddc64639644b0cc21e4c8217c5b999eba7d833008a95bf1a3359becc0158a9

See more details on using hashes here.

File details

Details for the file readPos-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: readPos-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • 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

Hashes for readPos-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0817e4f6f25e419654eba7c6d1e2a9ab11ae4d4a77d6bcce70980b8fb3c6d5ae
MD5 436d400e082036e64322c8791c39ea6a
BLAKE2b-256 baa04aa4f5e537ababef9712fa6866be28537fce847d8e44fadec4adbda2a139

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page