-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# .github/workflows/publish.yml | ||
|
||
name: Publish | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: npx jsr publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,85 @@ | ||
# pl2xl | ||
|
||
A lightweight library for reading and writing Excel files as Polars DataFrames. | ||
`pl2xl` enables seamless integration between Polars and Excel, allowing you to | ||
import data from Excel files directly into a Polars DataFrame and export | ||
DataFrames back to Excel. | ||
|
||
## Installation | ||
|
||
This library can be imported using the `jsr` import specifier and relies on the | ||
`nodejs-polars` package. | ||
|
||
### Importing the library in Deno | ||
|
||
```typescript | ||
import { readExcel, writeExcel } from "jsr:@jackfiszr/pl2xl@0.0.1"; | ||
import pl from "npm:nodejs-polars"; | ||
``` | ||
|
||
### Using the library in Node.js | ||
|
||
Install the library in your Node project using `npx jsr`: | ||
|
||
```bash | ||
npx jsr add @jackfiszr/pl2xl | ||
``` | ||
|
||
Then import and use it as follows: | ||
|
||
```typescript | ||
import { readExcel, writeExcel } from "@jackfiszr/pl2xl"; | ||
import pl from "nodejs-polars"; | ||
|
||
// Create a sample DataFrame | ||
const inputDf = pl.DataFrame({ | ||
"Name": ["Alice", "Bob", "Charlie"], | ||
"Age": [25, 30, 35], | ||
"City": ["New York", "Los Angeles", "Chicago"], | ||
}); | ||
|
||
// Write the DataFrame to an Excel file | ||
writeExcel(inputDf, "input.xlsx"); | ||
|
||
// Read the DataFrame back from the Excel file | ||
const df = readExcel("input.xlsx"); | ||
console.log("Read DataFrame:", df); | ||
|
||
// Modify the DataFrame by increasing the "Age" column by 1 | ||
const modifiedDf = df.withColumn( | ||
pl.col("Age").add(1).alias("Age"), | ||
); | ||
|
||
console.log("Modified DataFrame:", modifiedDf); | ||
|
||
// Write the modified DataFrame to a new Excel file | ||
writeExcel(modifiedDf, "output.xlsx"); | ||
console.log("Modified DataFrame written to output.xlsx"); | ||
``` | ||
|
||
## API | ||
|
||
### `readExcel(filePath: string): pl.DataFrame` | ||
|
||
Reads data from the first sheet of an Excel file and returns it as a Polars | ||
DataFrame. | ||
|
||
- `filePath`: The path to the Excel file to be read. | ||
|
||
**Returns**: A `pl.DataFrame` containing the data from the Excel file. | ||
|
||
### `writeExcel(df: pl.DataFrame, filePath: string): void` | ||
|
||
Writes a Polars DataFrame to an Excel file. | ||
|
||
- `df`: The Polars DataFrame to write to the file. | ||
- `filePath`: The path to save the Excel file. | ||
|
||
## Requirements | ||
|
||
- Deno (for Deno usage) or Node.js (for Node usage) | ||
- `nodejs-polars` and `xlsx` packages | ||
|
||
## License | ||
|
||
MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters