1

I have a dict of datarames dict_of_dfs.

I try two show first row from each dataset:

for colsKey, colsValue in dict_of_cols.items():
    dict_of_dfs['dt_'+str(colsKey)] = pd.DataFrame(colsValue)

for dfName, val in dict_of_dfs.items():
    row = dict_of_dfs[dfName].head(1)
    row

But it does not work for me.

This also does not return me output pandas frame:

for dfName in dict_of_dfs.keys():
    dict_of_dfs['dt_12'].head(1).to_string()
6
  • Add a printstatement: print(row) Commented May 25, 2022 at 13:45
  • Yes, it works but I see that like plain text not a frame Commented May 25, 2022 at 13:48
  • But this gives me right output: dict_of_dfs['dt_12'].head(1) Commented May 25, 2022 at 13:51
  • Maybe head() can not work in loop? Commented May 25, 2022 at 13:52
  • if you are working in a jupyter notebook use display() Commented May 25, 2022 at 13:54

1 Answer 1

1

I assume you are working in Jupyter Notebook. You can use the display function from IPython.display.

from IPython.display import display
for dfName, val in dict_of_dfs.items():
    display(val.head(1))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.