Take a df or csv and convert to text
Project description
Tabular_2_Text
Sometimes tabular data is just easier to read as text!
Tabular_2_Text is a Python package that converts tabular data (CSV files or pandas DataFrames) into a formatted text file. Each row from your table is converted into a clearly formatted text entry with labeled fields.
Features
- Convert CSV files directly to formatted text
- Convert pandas DataFrames to formatted text
- Clean, readable output format
- Automatic field labeling
- Simple, user-friendly interface
Installation
pip install tabular-2-text
Usage
Basic Usage
from tabular_2_text import tab2text
# Using a CSV file as input
tab2text("input.csv", "output.txt")
# Using a pandas DataFrame as input
import pandas as pd
df = pd.DataFrame({
'name': ['John Doe', 'Jane Smith'],
'age': [30, 25],
'city': ['New York', 'Los Angeles']
})
tab2text(df, "output.txt")
Example
Input CSV (employees.csv):
name,age,department,salary
John Doe,30,Engineering,75000
Jane Smith,28,Marketing,65000
Bob Johnson,35,Sales,70000
Python code:
from converter import tab2text
# Convert the CSV to text
tab2text("employees.csv", "employees_formatted.txt")
Output (employees_formatted.txt):
name: John Doe
age: 30
department: Engineering
salary: 75000
***********************************************
name: Jane Smith
age: 28
department: Marketing
salary: 65000
***********************************************
name: Bob Johnson
age: 35
department: Sales
salary: 70000
Function Parameters
tab2text(input_data, output_file_path)
input_data: Either a file path to a CSV file (string) or a pandas DataFrameoutput_file_path: The path where you want to save the output text file (string)
Returns
- Returns the path to the generated text file (string)
- Prints a confirmation message with the file location
Requirements
- Python 3.6 or higher
- pandas
Error Handling
The function will raise a ValueError if:
- The input is neither a string (file path) nor a pandas DataFrame
- The CSV file path is invalid
- The DataFrame is empty
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Common Use Cases
- Converting spreadsheet data to readable text format
- Preparing tabular data for document integration
- Creating human-readable exports from databases
- Formatting data for report generation
- Converting CSV exports to readable text
Tips
- Make sure your CSV files are properly formatted
- For large datasets, consider processing in chunks
- Check that your output filepath is writable
- Keep column names simple and readable for best results
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tabular_2_text-0.1.7.tar.gz.
File metadata
- Download URL: tabular_2_text-0.1.7.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e993c0ca2f5f65bd8b94fe34b69e9c39987244963dd873cb72821570eacbdb1
|
|
| MD5 |
cc86388576108183d8355d496f8a7283
|
|
| BLAKE2b-256 |
5bf8fe8c4c187612ec9339aab3706fe376ffddbd763df863e70acb44c29be139
|
File details
Details for the file tabular_2_text-0.1.7-py3-none-any.whl.
File metadata
- Download URL: tabular_2_text-0.1.7-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c31c4d717c70d01306705a30ad6d4cb1b7b0cee26cbb676536ce96571418c2b6
|
|
| MD5 |
ab919ce7db7fb31771d1d461d0780c52
|
|
| BLAKE2b-256 |
7137d22e6e43bdb079ae8c6a858c67d9c0991a5565a7cbe26fb321caab7b84e6
|