GithubHelp home page GithubHelp logo

polars-url's Introduction

polars-url

⚠️ WIP ⚠️

Some polars plugins to parse/extract fields from urls.


There are currently two plugins:

  • parse_url will take an input Series and a kwarg (field). It will parse the input str Series with Url::parse (from the url crate) and extract the field requested in the kwarg, e.g.:
with pl.Config(tbl_rows=-1, tbl_cols=-1, fmt_str_lengths=80):
    df = pl.DataFrame({
        'URLs': [
            'https://web.whatsapp.com/',
            'https://www.example.com:8080/path?query=example#fragment',
            'https://[2001:db8::1]:443/api/v1?query=value',
            'ftp://user:[email protected]:21/file/download',
            'http://example.com:80/path/to/resource?key=value#section1',
            'in case I dont see ya\\asd; foo',
            'good afternoon, good evening and good night\\sj@20.,[',
        ],
    })
    result = (df
              .with_columns(scheme=parse_url('URLs', field="scheme"))
              .with_columns(username=parse_url('URLs', field="username"))
              .with_columns(host=parse_url('URLs', field="host"))
              .with_columns(port=parse_url('URLs', field="port"))
              .with_columns(path=parse_url('URLs', field="path"))
              .with_columns(query=parse_url('URLs', field="query"))
              .with_columns(fragment=parse_url('URLs', field="fragment"))
              )
    print(result)

  • extract_field_from_series will take two input Series: one with the urls, another with the name of the field to be extracted from that row's url, e.g.:
with pl.Config(tbl_rows=-1, tbl_cols=-1, fmt_str_lengths=80):
    df = pl.DataFrame({
        'URLs': [
            'https://web.whatsapp.com/',
            'https://www.example.com:8080/path?query=example#fragment',
            'https://[2001:db8::1]:666/api/v1?query=value',
            'ftp://user:[email protected]:21/file/download',
            'http://example.com:80/path/to/resource?key=value#section1',
            'http://example.com:80/path/to/resource?key=value#section1',
        ],
        'extract': [
            'scheme',
            'host',
            'port',
            'path',
            'query',
            'fragment',
        ]
    })
    result = (df
              .with_columns(fields=extract_field_from_series('URLs', 'extract'))
              )
    print(result)

These are the results from both examples above, respectively:

Example usage showing the plugin extracting several url fields in separate columns, then another example showing a column with the field to be extracted and the result on its side

polars-url's People

Contributors

condekind avatar

Stargazers

Kamil Mielczarek avatar Thomas avatar Marco Edward Gorelli avatar

Watchers

 avatar

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.