Skip to main content

A utility library for file operations

Project description

pandas_appendunits

pandas_appendunits is a Python package for performing file operations easily. It provides functions to manipulate files such as getting paths of files with specific names or extensions in a directory, and merging multiple files into a single DataFrame.

Installation

You can install FileUtils using pip:

pip install pdappendunits

Functions

files_in_names

Get the paths of the files with the given names in the directory.

import os

def files_in_names(directory, file_names):
    """
    Get the paths of the files with the given names in the directory.
    """
    file_paths = []
    for file_name in file_names:
        file_path = os.path.join(directory, file_name)
        if os.path.exists(file_path):  # Check if the file exists
            file_paths.append(file_path)
        else:
            print(f"File '{file_name}' not found in directory '{directory}'.")
    return file_paths

files_in_extension

Get the paths of the files with the given extension in the directory.

import os

def files_in_extension(directory, extension):
    """
    Get the paths of the files with the given extension in the directory.
    """
    file_paths = []
    for file in os.listdir(directory):
        if file.endswith(extension):
            file_path = os.path.join(directory, file)
            file_paths.append(file_path)
    return file_paths

merge_files

Merge the files into a single DataFrame.

import pandas as pd

def merge_files(file_paths):
    """
    Merge the files into a single DataFrame.
    """
    file_list = []
    for file_path in file_paths:
        df = pd.read_csv(file_path)
        file_list.append(df)
    if file_list:
        return pd.concat(file_list, ignore_index=True)
    else:
        return None

Usage

Here's an example of how to use the functions:

import fileutils as fu

directory = "/path/to/your/directory"
file_names = ["file1.csv", "file2.csv"]  # List of file names
extension = ".csv"  # File extension

Get paths of files with specific names

file_paths = fu.files_in_names(directory, file_names)

Get paths of files with specific extension

file_paths_with_extension = fu.files_in_extension(directory, extension)

Merge files into a single DataFrame

data = fu.merge_files(file_paths_with_extension)

print(data)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pdappendunits-0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pdappendunits-0.2-py3-none-any.whl.

File metadata

  • Download URL: pdappendunits-0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for pdappendunits-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 207265ebc357eac7bd18529f93fbb5121ef48ca433e40a16cdec99175c42ff2b
MD5 7fd6af77a6290e0e8edfb17986a7fe76
BLAKE2b-256 2f43579b9f99723a2bbf65bb001e47206c8f6a9d3bf47609370fcfec9ba40ea0

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