CsvReader¶
Bases: InputElement
_value_type: type
property
¶
Get the CsvReader value type: Pandas DataFrame pd.DataFrame
.
value: Optional[pd.DataFrame]
property
¶
Returns:
Type | Description |
---|---|
Optional[pd.DataFrame]
|
The Pandas DataFrame loaded from the provided file path, otherwise None if the |
Optional[pd.DataFrame]
|
file does not exists. |
__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, tags=None, kwargs)
¶
A CSV-file reader returning a Pandas DataFrame and displayed as a table in Streamlit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
ID of the element. It must be unique as it is the key used to story data in
Project(), otherwise it will lead to conflicts at runtime in both execution and
Streamlit modes. The key will be transformed into snake case and slugified to avoid
any special character or whitespace. Note that an ID cannot start with |
required |
value |
Optional[Union[str, List[str]]]
|
Path to the CSV file. CSV file must exists, even for the Streamlit mode. |
required |
label |
Optional[str]
|
Label to display on top of the table. |
None
|
count |
Optional[Union[int, str]]
|
Specify the number of occurence of the widget. OneCode typically uses it for the
streamlit case. Note that if |
None
|
optional |
Union[bool, str]
|
Specify whether the value may be None. |
False
|
hide_when_disabled |
bool
|
If element is optional, set it to True to hide it from the interface, otherwise it will be shown disabled. |
False
|
tags |
Optional[List[str]]
|
Optional meta-data information about the expected file. This information is only
used by the |
None
|
**kwargs |
Any
|
Extra user meta-data to attach to the element. Argument names cannot overwrite
existing attributes or methods name such as |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if the |
AttributeError
|
if one the |
Example
import pandas as pd
from onecode import csv_reader, Mode, Project
Project().mode = Mode.EXECUTE
widget = csv_reader(
key="CsvReader",
value="/path/to/file.csv",
label="My CSV Reader",
tags=['CSV']
)
pd.testing.assert_frame_equal(widget, pd.read_csv("/path/to/file.csv"))
_validate(value)
¶
Raises:
Type | Description |
---|---|
ValueError
|
if the DataFrame is empty. |
imports()
staticmethod
¶
Returns:
Type | Description |
---|---|
List[str]
|
Python import statements required by the Streamlit code. |
streamlit(id)
¶
Returns:
Type | Description |
---|---|
str
|
The Streamlit code for a Pandas DataFrame ( |
Note
A file selector (st.file_uploader
) is provided on top of the table.