Skip to main content

Read files of any format into pandas with just read_file(**kwargs) method

Project description

Code README

Overview

This Python code provides a Loader class that simplifies the process of loading data from various file formats such as CSV, Parquet, and Excel (XLSX) using the pandas library. The code is designed to make it easy to read data from different file formats with a unified interface.

Prerequisites

Before using this code, make sure you have the following installed:

  • Python 3.x
  • pandas library

How to Use

To use the Loader class to read data from a file, follow these steps:

  1. Import the necessary libraries:

    import pandas as pd
    import numpy as np
    
  2. Create an instance of the Loader class by providing the file path as an argument to the constructor:

    file_path = "your_data.csv"  # Replace with the path to your data file
    data_loader = Loader(file_path)
    
  3. Use the read_file method to read the data from the specified file. You can pass any keyword arguments that are valid for the corresponding pandas read function (e.g., pd.read_csv, pd.read_parquet, or pd.read_excel):

    data = data_loader.read_file()
    
  4. The data variable now contains the loaded data from the file in a pandas DataFrame.

  5. You can also specify additional keyword arguments when calling read_file. For example:

    data = data_loader.read_file(header=0, sep=',')
    

Supported File Formats

The Loader class supports the following file formats:

  • CSV (Comma-Separated Values)
  • Parquet
  • Excel (XLSX)

Error Handling

  • If you create a Loader instance without providing a file path or with an unsupported file format, it will raise an AssertionError.

Example

Here's an example of how to use the Loader class to read a CSV file:

# Import libraries and create a Loader instance
import pandas as pd
import numpy as np
from loader import Loader  # Import the Loader class from your module

file_path = "data.csv"
data_loader = Loader(file_path)

# Read the CSV file
data = data_loader.read_file()

# Now 'data' contains the loaded data in a pandas DataFrame
print(data.head())

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

fileLoader-0.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

fileLoader-0.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file fileLoader-0.0.0.tar.gz.

File metadata

  • Download URL: fileLoader-0.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for fileLoader-0.0.0.tar.gz
Algorithm Hash digest
SHA256 3cb97f47ea1d2b91a8dfce1090a3d17e8400c47e3cc3a500f4768817fa3b17fa
MD5 9e1d3fe731fa3f190e4d7d0c3b1a3810
BLAKE2b-256 ae247c22f689a32dc295fcd162ffb074a3e56f1b170e2fe39d264ff12df346ff

See more details on using hashes here.

File details

Details for the file fileLoader-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: fileLoader-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for fileLoader-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 483c3fd21711aeab155f77b1203b67d8f50d4dc30ba0ac76d58c25cca00deac1
MD5 7ae11141189cb9cbf98943a553ba87d8
BLAKE2b-256 2cf2a8369363f9c3ec7f6562905c72f7b2f9be07947d0140c08d268b69dd3825

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