Python Forum
How to compare boxplot bw many data frames?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare boxplot bw many data frames?
#1
I have many data frame like table below:
what I want is plot box plot of each column & compare line by line.
   
I'm new member, can you help me.
Thanks so much!

Attached Files

.xlsx   Book1.xlsx (Size: 17.42 KB / Downloads: 1)
Reply
#2
what have you tried so far?
Please show code, working or not.
Reply
#3
(May-30-2023, 12:21 PM)Larz60+ Wrote: what have you tried so far?
Please show code, working or not.
My code already worked, but I want shortened this code, because have many column need to check.
Do we have idea to resolve it?
import matplotlib.pyplot as plt
import pandas as pd

file = 'E:/Document/python/Book1.xlsx'
df = pd.read_excel(file)
data1_tester1 = df[df['Tester']=='Tester 1']['Data1']
data1_tester2 = df[df['Tester']=='Tester 2']['Data1']
data1_tester3 = df[df['Tester']=='Tester 3']['Data1']
data1_tester4 = df[df['Tester']=='Tester 4']['Data1']
data1_tester5 = df[df['Tester']=='Tester 5']['Data1']
data2_tester1 = df[df['Tester']=='Tester 1']['Data2']
data2_tester2 = df[df['Tester']=='Tester 2']['Data2']
data2_tester3 = df[df['Tester']=='Tester 3']['Data2']
data2_tester4 = df[df['Tester']=='Tester 4']['Data2']
data2_tester5 = df[df['Tester']=='Tester 5']['Data2']
ax1 = plt.subplot(2,1,1)
ax1.boxplot([data1_tester1,data1_tester2,data1_tester3,data1_tester4,data1_tester5])
ax1.set_xticklabels('')
ax2 = plt.subplot(2,1,2)
ax2.boxplot([data2_tester1,data2_tester2,data2_tester3,data2_tester4,data2_tester5],labels=['Tester 1','Tester 2','Tester 3','Tester 4','Tester 5'])
plt.show()

Attached Files

.xlsx   Book1.xlsx (Size: 18.04 KB / Downloads: 3)
Reply
#4
Please tell me what your goal is (what you expect the output to look like). The code as presented looks rather bazzar.
vanphuht91 likes this post
Reply
#5
(May-30-2023, 09:47 PM)Larz60+ Wrote: Please tell me what your goal is (what you expect the output to look like). The code as presented looks rather bazzar.

Actually, my code is working. But what I want is shortern code at assign variables step. Because, we have so many collumn need to check.
If we only assign manual row by row. It will be 10 data * 5 tester = 50 rows need to manual assign at this examples
I can't image how we assign variables for 100 data & 10 tester Snooty Snooty Snooty
Can we use loop or have any idea to resolve it?
This is result of my code:
   
Reply
#6
You can replace the data load as follows

you can probably also iterate the plot in a similar fashion

import matplotlib.pyplot as plt
import pandas as pd
 
tester = {}

file = 'E:/Document/python/Book1.xlsx'
df = pd.read_excel(file)

for name in df.columns:
    if name.startswith('Data'):
        new_colname = f"{name}_tester{name[4:]}"
        tester[name] = df.filter(items=[name])

# How to use:
print(tester.keys())
print(f"\n{tester['Data1']}")
print(f"\n{tester['Data2']}")

# ax1 = plt.subplot(2,1,1)
# ax1.boxplot([data1_tester1,data1_tester2,data1_tester3,data1_tester4,data1_tester5])
# ax1.set_xticklabels('')
# ax2 = plt.subplot(2,1,2)
# ax2.boxplot([data2_tester1,data2_tester2,data2_tester3,data2_tester4,data2_tester5],labels=['Tester 1','Tester 2','Tester 3','Tester 4','Tester 5'])
# plt.show()
output of printf statements above:
Output:
dict_keys(['Data1', 'Data2', 'Data3', 'Data4', 'Data5', 'Data6', 'Data7', 'Data8', 'Data9', 'Data10']) Data1 0 6.91 1 5.79 2 7.12 3 7.61 4 7.70 .. ... 94 7.92 95 6.66 96 7.07 97 5.64 98 7.18 [99 rows x 1 columns] Data2 0 20.96 1 18.78 2 21.05 3 21.96 4 20.47 .. ... 94 19.92 95 21.09 96 20.94 97 18.86 98 18.41 [99 rows x 1 columns]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  merging two data frames yk303 1 6,838 Jan-27-2021, 03:02 AM
Last Post: rennerom
  save video frames into pandas data-frame tofi 0 2,678 Oct-18-2018, 07:02 PM
Last Post: tofi
  Compare 2 Csv data sets, identify record with latest date MJUk 11 6,204 Jan-06-2018, 09:23 PM
Last Post: MJUk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020