Skip to content

Commit

Permalink
Add csv_to_df function
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Nov 27, 2023
1 parent c545c64 commit c2cd709
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dj_notebook/shell_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


import base64
import io
import pathlib
import typing

import IPython
Expand Down Expand Up @@ -143,6 +145,14 @@ def model_graph(self, model: django_models.Model, max_nodes: int = 20) -> None:
)
display_mermaid(output)

def csv_to_df(self, filepath_or_string: pathlib.Path | str) -> pd.DataFrame:
"""Read a CSV file into a Pandas DataFrame."""
if isinstance(filepath_or_string, pathlib.Path):
return pd.read_csv(filepath_or_string)
buffer = io.StringIO(filepath_or_string)
return pd.read_csv(buffer)



def get_node_for_model(graph, model: django_models.Model):
try:
Expand Down

0 comments on commit c2cd709

Please sign in to comment.