How to read specific data(i.e., rows and columns) from a parquet file in gramex formhandler?

43 Views Asked by At

I want to read a parquet file with only certain columns and certain rows to formhandler in Gramex.

1

There are 1 best solutions below

1
On

Suppose you have city.parquet, and you want to:

  • filter rows where country is Japan.
  • filter columns lat and long,

APPROACH #1 - Client-side: Use this configuration:

url:
  data:
    pattern: /data
    handler: FormHandler
    kwargs:
      url: file.parquet

Now use the URL /data?country=Japan&_c=lat&_c=long. This will filter by the required rows and columns.

APPROACH #2 - Server side: Use this configuration

url:
  data:
    pattern: /data
    handler: FormHandler
    kwargs:
      url: file.parquet
      function: data[data.country == 'Japan'][['lat', 'long']]

Now the URL /data returns only the required rows and columns.

When to use which approach:

If you want the user or the application to control the rows and columns, use the client-side approach.

If you want to securely share only the required data, use the server-side approach.