1

I have a folder having multiple CSV files. Each file has 3 columns ('real','user','sys')each column has 10 time values(float) in the rows.My target is to read these csv files from the folder and make a box-whisker graph to compare the values of each csv file. I wrote the following python code and it gives me multiple(equal to the number of files) separate graphs. By removing plt.show() out of the loop only last graph is displayed.

I want these graphs to be merged in one graph and each file name to be the labels defining which box-whisker is for which file. Kindly help.

import csv
import numpy as np
import pandas
import matplotlib.pyplot as plt
import glob

files = glob.glob ('/Users/Desktop/sample/*.csv')
print files

for file in files:
    df = pandas.read_csv(file, sep=',')

    LABELS = ["real", "user", "sys"]

    plt.title('Time Taken by Classifier')
    plt.xlabel('Time_Types')
    plt.ylabel('Time_Value in (sec)')


    df.boxplot()

    plt.show()
user6232789
  • 11
  • 1
  • 2

1 Answers1

1

You may want to try something along these lines:

import pandas as pd
data = pd.DataFrame()
for file in files:

    df = pandas.read_csv(file, sep=',')
    df['file'] = file
    data = pd.concat([data, df])


LABELS = ["real", "user", "sys"]

plt.title('Time Taken by Classifier')
plt.xlabel('Time_Types')
plt.ylabel('Time_Value in (sec)')


data.boxplot(by='file')

plt.show()

See pd.DataFrame.boxplot() docs and underlying matplotlib implementation for how you can use the keyword args to modify layout.

Stefan
  • 41,759
  • 13
  • 76
  • 81
  • Did this answer your question after all? – Stefan May 18 '16 at 18:18
  • I got your point in this answer by concatenation. My case is somehow similar but with some differences. I'm reading subfolders to do some stuff then plotting. Now I could plot one by one but I can not make them collected. [link](https://stackoverflow.com/questions/62291164/how-to-collect-plots-and-label-axis-in-boxplot) – Mir.Emad Jun 10 '20 at 08:59