> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rho.store/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload strategies

> Different ways to upload your changes

There are four different upload strategies available:

1. New table
2. Append
3. Replace
4. Merge

### 1. New table

New table is the default strategy. It will always create a new table.

```python main.py theme={null}
import pandas as pd

# example data
emissions_df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/Emissions%20Data.csv")

table = rho_client.store_df(
    emissions_df,
    name="emissions_data",
    strategy="NEW_TABLE"  # default strategy, can be omitted
)
print(table.client_url)
```

### 2. Append

Append strategy will append the data to the existing table. To append, you need to specify the `table_id` of the table you want to append to.

```python main.py theme={null}
import pandas as pd

# example data
initial_data = pd.DataFrame({"value": [i for i in range(10, start=1)]})

# create new table
table = rho_client.store_df(
    initial_data,
    name="append_demo"
)
# append more data
more_data = pd.DataFrame({"value": [i for i in range(10, start=11)]})
table = rho_client.store_df(
    more_data,
    table_id=table.table_id,
    strategy="APPEND"
)
print(table.client_url)
```

The method is also available on the `Table` object:

<CodeGroup>
  ```python main.py theme={null}
  more_data = pd.DataFrame({"value": [i for i in range(10, start=11)]})
  table.append(more_data)
  print(table.client_url)
  ```

  ```python full_example.py theme={null}
  import pandas as pd
  from rho_store import RhoClient

  API_KEY = "YOUR_API_KEY"
  rho_client = RhoClient(api_key=API_KEY)

  # example data
  initial_data = pd.DataFrame({"value": [i for i in range(10, start=1)]})

  # create new table
  table = rho_client.store_df(
      initial_data,
      name="append_demo"
  )
  # append more data
  more_data = pd.DataFrame({"value": [i for i in range(10, start=11)]})
  table.append(more_data)
  print(table.client_url)
  ```
</CodeGroup>

### 3. Replace

The replace strategy will replace the data in the existing table. To replace, you need to specify the `table_id` of the table you want to replace.

```python main.py theme={null}
import pandas as pd

# example data
initial_data = pd.DataFrame({"value": [i for i in range(10, start=1)]})

# create new table
table = rho_client.store_df(
    initial_data,
    name="replace_demo"
)
# replace the data
new_data = pd.DataFrame({"value": [i for i in range(10, start=11)]})
table = rho_client.store_df(
    new_data,
    table_id=table.table_id,
    strategy="REPLACE"
)
print(table.client_url)
```

There is a shorthand for the method available on the `Table`-object:

<CodeGroup>
  ```python main.py theme={null}
  new_data = pd.DataFrame({"value": [i for i in range(10, start=11)]})
  table.replace(new_data)
  print(table.client_url)
  ```

  ```python full_example.py theme={null}
  import pandas as pd
  from rho_store import RhoClient

  API_KEY = "YOUR_API_KEY"
  rho_client = RhoClient(api_key=API_KEY)

  # example data
  initial_data = pd.DataFrame({"value": [i for i in range(10, start=1)]})

  # create new table
  table = rho_client.store_df(
      initial_data,
      name="replace_demo"
  )
  # replace the data
  new_data = pd.DataFrame({"value": [i for i in range(10, start=11)]})
  table.replace(new_data)
  print(table.client_url)
  ```
</CodeGroup>

### 4. Merge

The merge strategy will merge the data in the existing table. To merge, you need to specify the `table_id` of the table you want to merge.
You also need to specify the column to merge on. The merge strategy will merge the data on the specified column.
The merge-column must be a unique column in both tables.

```python main.py theme={null}
import pandas as pd

# example data
initial_data = pd.DataFrame({"value": [i for i in range(10, start=1)]})

# create new table
table = rho_client.store_df(
    initial_data,
    name="replace_demo"
)
# merge on specific column
new_data = pd.DataFrame({"value": [i for i in range(20, start=1)]})
table = rho_client.store_df(
    new_data,
    table_id=table.table_id,
    strategy="MERGE",
    merge_options={"column": "value"}
)
print(table.client_url)
```

There is a shorthand for the method available on the `Table`-object:

<CodeGroup>
  ```python main.py theme={null}
  new_data = pd.DataFrame({"value": [i for i in range(30, start=1)]})
  table.merge(new_data, column="value")
  print(table.client_url)
  ```

  ```python full_example.py theme={null}
  import pandas as pd
  from rho_store import RhoClient

  API_KEY = "YOUR_API_KEY"
  rho_client = RhoClient(api_key=API_KEY)

  # example data
  initial_data = pd.DataFrame({"value": [i for i in range(10, start=1)]})

  # create new table
  table = rho_client.store_df(
      initial_data,
      name="replace_demo"
  )
  # merge on specific column
  new_data = pd.DataFrame({"value": [i for i in range(30, start=1)]})
  table.merge(new_data, column="value")
  print(table.client_url)
  ```
</CodeGroup>
