Home > other >  can't read csv file using pd.read_csv() method in test class
can't read csv file using pd.read_csv() method in test class

Time:11-01

import sys
import numpy as np
import pandas as pd

sys.path.insert(0, sys.argv[2])
sys.path.insert(1, sys.argv[3])

from training import CustomerSegmentation

class TestCustomerSegmentation:

    dataset = pd.read_csv(
    sys.path.pop(1),
    parse_dates=["InvoiceDate"],
    )

then by giving command line arguments:

python3 -m pytest test_training.py "customer-segmentation-v1" "customer-segmentation-v1/customer_data.csv"

it gives an error:

ERROR: not found: /customer-segmentation-v1/customer_data.csv (no name '/customer-segmentation-v1/customer_data.csv' in any of [])

I want my test class to read the csv data file that is present on the path given as command line argument.

CodePudding user response:

How about creating a virtual environment for your project first and running the codes in the Virtual environment.

py -m venv environment
environment\Scripts\activate

Try creating an environment and run your project inside the environment.

CodePudding user response:

you must add the file into the same folder. or maybe this link is useful for you here https://www.machinelearningplus.com/pandas/pandas-read_csv-completed/

  • Related