Giter VIP home page Giter VIP logo

Comments (3)

liferoad avatar liferoad commented on August 16, 2024

One workaround is to convert the value using your own function, for example,

with beam.Pipeline() as pipeline:
    (
        pipeline
        | beam.io.ReadFromCsv("input.csv", dtype=None)
        | beam.Map(lambda x: [str(t) for t in x])
        | beam.Map(print)
    )

from beam.

sorensenjs avatar sorensenjs commented on August 16, 2024

That workaround code example doesn't work, because ReadFromCsv and WriteToCsv both produce/require schemas.

Even if you were to use a ._asdict() like so

( pipeline | beam.io.ReadFromCsv('/tmp/input.csv', dtype=str)
      | beam.Map(lambda x: x._asdict())
      | beam.Map(print)

Conversion to str element by element will result in 'None' values instead of empty strings. Values interpreted as floating point may loose precision.

{'a': 'text', 'b': 1, 'c': 21, 'd': 5945023, 'e': 376974, 'f': 0, 'g': 0, 'h': 0, 'i': 1, 'j': 2, 'k': 0, 'l': 4, 'm': None, 'n': None, 'o': None, 'p': None, 'q': None, 'r': None}
Elapsed time  0:00:00.878320
{'a': 'text', 'b': '1', 'c': '21', 'd': '5945023', 'e': '376974', 'f': '0', 'g': '0', 'h': '0', 'i': '1', 'j': '2', 'k': '0', 'l': '4', 'm': None, 'n': None, 'o': None, 'p': None, 'q': None, 'r': None}
Elapsed time  0:00:24.243182

from beam.

liferoad avatar liferoad commented on August 16, 2024

My example just shows that you can do the conversation without using dtype=str. If you need to keep the schemas, you could do something like:

with beam.Pipeline() as pipeline:
    (
        pipeline
        | beam.io.ReadFromCsv("input.csv", dtype=None)
        | beam.Map(lambda x: beam.Row(a=x.a, b=str(x.b)))
        | beam.io.WriteToCsv("output1.csv")
    )

from beam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.