An empty DataFrame named test
is created using pandas. Data is then assigned to two columns, image
and label
, from the results of the createdataframe
function called with the TEST_DIR
argument.
test = pd.DataFrame()
test['image'], test['label'] = createdataframe(TEST_DIR)
import pandas as pd
def load_test_data(test_dir):
try:
# Create a pandas DataFrame from the provided test directory
image_data, label_data = createdataframe(test_dir)
# Create a dictionary to store the data
data = {
'image': image_data,
"label": label_data
}
# Convert the dictionary to a DataFrame
test_df = pd.DataFrame(data)
# Return the DataFrame
return test_df
except Exception as e:
# Log any exceptions and return None
print(f"An error occurred: {str(e)}")
return None
# Example usage:
test_df = load_test_data(TEST_DIR)
The code snippet assumes that the pandas library (pd
) has been imported.
test = pd.DataFrame()
test
.test['image'], test['label'] = createdataframe(TEST_DIR)
createdataframe
function with the TEST_DIR
argument.test
DataFrame:
test['image']
: the first returned value from createdataframe
.test['label']
: the second returned value from createdataframe
.