Read csv file and save images from the output I have created some code that reads my CSV file and converts the dataset to a grayscale image. I want to know if there is any possible way to read through each row in the dataset and save each of the images created from the rows?
So far, I have got this code that reads the CSV files and creates an image using .imshow
import pandas as pd 
import numpy as np 
from sklearn.datasets import load_digits
from keras.preprocessing.image import array_to_img
import matplotlib.pyplot as plt

data_path = &quot;dataset_malwares.csv&quot;

data = pd.read_csv(data_path);

label = data.Malware.values

data = data.drop(&quot;Malware&quot;, axis=1)
data = data.drop(&quot;Name&quot;, axis=1)
data = data.values
data = data.reshape(data.shape[0], data.shape[1], 1)
data = np.tile(data, (1, data.shape[1]))

plt.imshow(data[1], cmap=&quot;gray&quot;)

plt.title(&quot;label: {0:}&quot;.format(label[1]))
plt.show()

print(data[0].shape)

I want to go through the dataset and save each image but not too sure where to start. Any suggestions would be great. Thanks :)
Rows/format of the data - I've provided a shared version of the dataset:
https://1drv.ms/x/s!AqFNg8FC48SSgtZSObDmmGHs3utWog
Are you looking to simply save the file produced by plt.imshow? If yes, then you should be able to use plt.savefig as follows:
plt.imshow(data[1], cmap=&quot;gray&quot;)
plt.title(&quot;label: {0:}&quot;.format(label[1]))
plt.savefig(&quot;output_image.png&quot;)
plt.show()

You can either remove or keep the plt.show() call depending on whether you want the image to still be shown or just save the image.
EDIT: If you want to do this for all rows you can just loop through the numpy array as follows:
for i in range(data.shape[0])):
    plt.imshow(data[i], cmap=&quot;gray&quot;)
    plt.title(&quot;label: {0:}&quot;.format(label[1]))
    plt.savefig(f&quot;output_image_{i}.png&quot;)
    plt.close()