> For the complete documentation index, see [llms.txt](https://www.dicas-de-django.com.br/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.dicas-de-django.com.br/097-31-import-csv-pandas.md).

# Dica 31 - Importando CSV com Pandas

[![](/files/-MfuAP1e7W4erW9hf6Ic)](https://youtu.be/SaCCzTRSuYg)

<https://towardsdatascience.com/pandas-vs-dask-vs-datatable-a-performance-comparison-for-processing-csv-files-3b0e0e98215e>

```
pip install pandas
pip freeze | grep pandas >> requirements.txt

python manage.py shell_plus --notebook
```

```python
import pandas as pd

df = pd.read_csv('/tmp/products.csv')

df

df.max()

df.min()

Product.objects.all().delete()

def save_data(data):
    '''
    Salva os dados no banco.
    '''
    aux = []
    for item in data:
        title = item.get('title')
        price = item.get('price')
        obj = Product(
            title=title,
            price=price,
        )
        aux.append(obj)

    Product.objects.bulk_create(aux)

data = []

for row in df.itertuples():
    _dict = dict(title=row.title, price=row.price)
    data.append(_dict)

data

save_data(data)

Product.objects.all().count()
```
