Home python строка не найдена

строка не найдена




How to select the value of several DataFrame columns on the same graph with Seaborn?
Below is not a working code. It correctly displays the schedule for one column only, and you want to display several columns as below for example.

import pandas as pd
Import Matplotlib.pyPlot AS PLT
Import Seaborn AS SNS
C1 = [0.3, 0.5, 0, 0.9]
C2 = [0.7, 0, 0.1, 0]
DCT = {'C1': C1, 'C2': C2}
DF = PD.DataFrame (DCT)
Print (DF)
SNS.BarPlot (x = df.index.Values, Y = 'C1', DATA = DF)
# SNS.BarPlot (x = df.index.Values, Y = 'C2', Data = DF)
Plt.Show ()

Desired Graph

Answer 1, Authority 100%

Approximate option. Probably, you can still somehow beautiful, but not yet invented:

df1 = df.stack (). Reset_index (Level = 1)
df1.columns = ['C', 'Value']
SNS.BarPlot (x = df1.index.Values, Y = 'Value', Hue = 'C', Data = DF1)
Plt.Show ()

That is, you need to make such a DataFrame so that you can use the hue split columns on C1 and C2 . In DF1 , I got the following:

c value
0 C1 0.3.
0 C2 0.7.
1 C1 0.5.
1 C2 0.0.
2 C1 0.0.
2 C2 0.1.
3 C1 0.9.
3 C2 0.0.

Answer 2, Authority 100%

By the way, if seaborn is not a prerequisite, then everything is simple:

df.plot (kind = 'bar');
# or df.plot.bar ();

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions