question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cast int cell to string in excel file

See original GitHub issue

Let’s say I want to parse the attached file. It has in the A column string or int, but I want every cells of that column to be string.

I tried with this package.yaml

resources:
  - name: example
    type: table
    path: example.xlsx
    scheme: file
    format: xlsx
    encoding: utf-8
    mediatype: application/vnd.ms-excel
    schema:
      fields:
        - name: A
          type: string
        - name: B
          type: string
    pipeline:
      steps:
        - type: table-normalize
        - type: field-merge
          fromNames:
            - A
            - B
          name: AB

and runned this python script

from frictionless import Package

p = Package.from_descriptor('package-issue.yaml')

p.extract()

for r in p.resources:
    r.transform()
    print(r.to_view())

I have this error when I try to tranform it with field-merge

frictionless.exception.FrictionlessException: [step-error] Step is not valid: "field_merge" raises "sequence item 0: expected str instance, NoneType found" 

Is there a way to cast all ints in string ?

example.xlsx

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
yohanbonifacecommented, Sep 21, 2022

@shashigharti we have an ETL where we ingest data that we do not produce. The dataset file and format is known, but we cannot change it.

In other words, we want to be able to import any dataset from anywhere on the Internet, “just” by defining a “schema file” on our side that would give to our ETL the rules needed to “normalize” the data before importing it in our database. By normalizing, I mean making sure for example that an int column only contains int, or mapping “pseudo booleans” to a real boolean column, or making sure that some administrative codes are valid, etc.

The ETL output is a normalized table in a postgresql database (each resource ends in a separate table).

To give a bit more details: we currently have our own code base, very similar to Frictionless, and we are evaluating the opportunity to use Frictionless, instead of reinventing the wheel.

To have an example of how we describe our ETL steps currently: https://datahub.incubateur.tech/infrastructure/insitu/-/blob/main/insitu/datasets/numerique.yml

Hope this helps! 😃

0reactions
rollcommented, Nov 9, 2022

We’re releasing frictionless@5.0.0b11 that now supports formats.ExcelControl.stringified:

resources:
  - name: example
    type: table
    path: example.xlsx
    scheme: file
    format: xlsx
    encoding: utf-8
    mediatype: application/vnd.ms-excel
    dialect:
      excel:
        stringified: true
    schema:
      fields:
        - name: A
          type: string
        - name: B
          type: string
    pipeline:
      steps:
        - type: table-normalize
        - type: field-merge
          fromNames:
            - A
            - B
          name: AB
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert number to text in Excel - 4 quick ways - Ablebits
Convert number to string using the Excel TEXT function to adjust the way your numbers will be displayed, or use Format Cells and...
Read more >
How to change or convert number to text in Excel?
1. Select the numbers that you want to convert to text. 2. Right click the selected range, and choose the Format Cells item...
Read more >
Convert numbers stored as text to numbers - Microsoft Support
Press CTRL + C to copy the cell. Select the cells that have numbers stored as text. On the Home tab, click Paste...
Read more >
Converting cell content to string data type in Excel using C# ...
get value from cell: var cellValue = (string)(excelWorksheet.Cells[10, 2] as Excel.Range).Value; · write to cell again (already string) or write ...
Read more >
VBA Convert Integer (Number) to String - Automate Excel
VBA Code Examples. In Depth Tutorials, yes. PowerPoint VBA Macro Examples & Tutorial · Sorting · Find and Find and Replace · Cheat...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found