pandas boxplot:交换框放置用于比较

时间:2015-08-26 10:01:05

标签: python pandas boxplot

app.directive('appUsername', function() {
  return {
    require: 'ngModel',
    link: function (scope, elm, attrs, ctrl) {
      var ref = new Firebase("https://<MY-APP>.firebaseio.com");
      ctrl.$asyncValidators.appUsername = function (modelValue, viewValue) {
        if (ctrl.$isEmpty(modelValue)) {
          // consider empty model valid
          return true;
        }
        var q = ref.child('users').orderByChild('username').equalTo(modelValue);
        q.once('value', function (snapshot) {
          if (snapshot.val() === null) {
            // username does not yet exist, go ahead and add new user
            return true;
          } else {
            // username already exists, ask user for a different name
            return false;
          }
        });
      };
    };
  };
});

给我一​​个这样的情节 enter image description here

我想比较“原始”和“新”,如何安排将两个“0”框放在一个面板中,将两个“1”框放在另一个面板中?当然,用标签交换标签。

由于

1 个答案:

答案 0 :(得分:2)

以下是要演示的示例数据集。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


# simulate some artificial data
# ==========================================
np.random.seed(0)
df = pd.DataFrame(np.random.rand(10,2), columns=['original', 'new'] )
df['by column'] = pd.Series([0,0,0,0,1,1,1,1,1,1])

# your original plot
ax = df.boxplot(['original', 'new'], by='by column', figsize=(12,6))

enter image description here

要获得所需的输出,请明确使用groupby boxplot,以便我们遍历所有子组,并为每个子组绘制boxplot

ax = df[['original', 'new']].groupby(df['by column']).boxplot(figsize=(12,6))

enter image description here