reflex icon indicating copy to clipboard operation
reflex copied to clipboard

pc.data_table columns props aren't working with pd.DataFrame as a list of dictionaries

Open sapanp007 opened this issue 3 years ago β€’ 2 comments

Describe the bug pc.data_table columns props aren't working with pd.DataFrame as a list of dictionaries

To Reproduce ` import pynecone as pc import pandas as pd

class State(pc.State): stbd=pd.DataFrame([ {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}, {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}, {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}]) def index(): return pc.data_table( data=State.stbd, columns=["k3", "k2"], pagination=True, search=True, ) app = pc.App(state=State) app.add_page(index,) app.compile() `

Expected behavior Fields mentioned in columns=["k3", "k2"] should be displayed in the same order.

Screenshots All the fields in the list of dictionaries are displayed.

** Specifics (please complete the following information):**

  • Python Version: 3.8
  • Pynecone Version: 0.1.16
  • OS:
  • Browser (Optional):

Additional context Add any other context about the problem here.

sapanp007 avatar Feb 17 '23 05:02 sapanp007

When I fetch data from MongoDB using pymongo I can restrict the fields by using projection, however, as the dictionary is an unordered data structure, "columns" in data_table would be helpful to display the fields in the required order.

sapanp007 avatar Feb 17 '23 05:02 sapanp007

I think this is a similar issue to #555 im looking into it right now

Alek99 avatar Feb 17 '23 05:02 Alek99

You dont need specify a column when the data is a pandas dataframe, The column values are automatically inferred.

ElijahAhianyo avatar Aug 18 '23 16:08 ElijahAhianyo