Any suitable way to describe the distributions of 2 Pandas Dataframes visually/graphically? The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsHow to graphically present the statistical interpretations when using Kolmogorov–Smirnov test (K-S) test?pandas dataframes memoryQuick way to visually explore data?Concatenate dataframes PandasIs there a package for using SQL to manipulate Pandas dataframes in Python?What’s the best way to save many pandas dataframes together?Is there any way to collect categorical features quickly in Julia DataFrames?Spearmanr on two pandas dataframesPandas: How can I merge two dataframes?Joining two dataframes on the basis of specific conditionsSVR is giving same prediction for all features

How should I replace vector<uint8_t>::const_iterator in an API?

Why not take a picture of a closer black hole?

Simulating Exploding Dice

How does this infinite series simplify to an integral?

Do warforged have souls?

system() function string length limit

Mortgage adviser recommends a longer term than necessary combined with overpayments

Why does the Event Horizon Telescope (EHT) not include telescopes from Africa, Asia or Australia?

Windows 10: How to Lock (not sleep) laptop on lid close?

What are these Gizmos at Izaña Atmospheric Research Center in Spain?

Finding the path in a graph from A to B then back to A with a minimum of shared edges

How are presidential pardons supposed to be used?

Difference between "generating set" and free product?

Can smartphones with the same camera sensor have different image quality?

Can the DM override racial traits?

Change bounding box of math glyphs in LuaTeX

Typeface like Times New Roman but with "tied" percent sign

What is special about square numbers here?

Are spiders unable to hurt humans, especially very small spiders?

How can I protect witches in combat who wear limited clothing?

Wall plug outlet change

Does Parliament hold absolute power in the UK?

How is simplicity better than precision and clarity in prose?

Why did all the guest students take carriages to the Yule Ball?



Any suitable way to describe the distributions of 2 Pandas Dataframes visually/graphically?



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsHow to graphically present the statistical interpretations when using Kolmogorov–Smirnov test (K-S) test?pandas dataframes memoryQuick way to visually explore data?Concatenate dataframes PandasIs there a package for using SQL to manipulate Pandas dataframes in Python?What’s the best way to save many pandas dataframes together?Is there any way to collect categorical features quickly in Julia DataFrames?Spearmanr on two pandas dataframesPandas: How can I merge two dataframes?Joining two dataframes on the basis of specific conditionsSVR is giving same prediction for all features










1












$begingroup$


I am aware of the fact that the Pandas Dataframe's Statistical description can easily be obtained using df.describe(). I am having 2 dataframes of the same dimensions (i.e. 102 columns and 800000 rows for both the dataframes). I would like to depict the fact visually that the 2 dataframes are very similar/have a statistically similar distribution.



I am not sure of how this can be done visually/graphically in Python. The df.describe method provides count, mean, std, min, 25 %, 50 %, 75 % and max values for the dataframes, but it is difficult to infer from in the first instance. I would prefer a visual/graphical method of any type (I am not sure if Boxplot can help?). Any suggested method along with a Minimum Workable Example would be highly appreciated. Cheers!



Presently,



# df1 is dataframe 1
# df2 is dataframe 2
df1.describe() # this gives statistical values of df1 dataframe
df2.describe() # this gives statistical values of df2 dataframe









share|improve this question









$endgroup$
















    1












    $begingroup$


    I am aware of the fact that the Pandas Dataframe's Statistical description can easily be obtained using df.describe(). I am having 2 dataframes of the same dimensions (i.e. 102 columns and 800000 rows for both the dataframes). I would like to depict the fact visually that the 2 dataframes are very similar/have a statistically similar distribution.



    I am not sure of how this can be done visually/graphically in Python. The df.describe method provides count, mean, std, min, 25 %, 50 %, 75 % and max values for the dataframes, but it is difficult to infer from in the first instance. I would prefer a visual/graphical method of any type (I am not sure if Boxplot can help?). Any suggested method along with a Minimum Workable Example would be highly appreciated. Cheers!



    Presently,



    # df1 is dataframe 1
    # df2 is dataframe 2
    df1.describe() # this gives statistical values of df1 dataframe
    df2.describe() # this gives statistical values of df2 dataframe









    share|improve this question









    $endgroup$














      1












      1








      1


      1



      $begingroup$


      I am aware of the fact that the Pandas Dataframe's Statistical description can easily be obtained using df.describe(). I am having 2 dataframes of the same dimensions (i.e. 102 columns and 800000 rows for both the dataframes). I would like to depict the fact visually that the 2 dataframes are very similar/have a statistically similar distribution.



      I am not sure of how this can be done visually/graphically in Python. The df.describe method provides count, mean, std, min, 25 %, 50 %, 75 % and max values for the dataframes, but it is difficult to infer from in the first instance. I would prefer a visual/graphical method of any type (I am not sure if Boxplot can help?). Any suggested method along with a Minimum Workable Example would be highly appreciated. Cheers!



      Presently,



      # df1 is dataframe 1
      # df2 is dataframe 2
      df1.describe() # this gives statistical values of df1 dataframe
      df2.describe() # this gives statistical values of df2 dataframe









      share|improve this question









      $endgroup$




      I am aware of the fact that the Pandas Dataframe's Statistical description can easily be obtained using df.describe(). I am having 2 dataframes of the same dimensions (i.e. 102 columns and 800000 rows for both the dataframes). I would like to depict the fact visually that the 2 dataframes are very similar/have a statistically similar distribution.



      I am not sure of how this can be done visually/graphically in Python. The df.describe method provides count, mean, std, min, 25 %, 50 %, 75 % and max values for the dataframes, but it is difficult to infer from in the first instance. I would prefer a visual/graphical method of any type (I am not sure if Boxplot can help?). Any suggested method along with a Minimum Workable Example would be highly appreciated. Cheers!



      Presently,



      # df1 is dataframe 1
      # df2 is dataframe 2
      df1.describe() # this gives statistical values of df1 dataframe
      df2.describe() # this gives statistical values of df2 dataframe






      python pandas visualization dataframe matplotlib






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 31 at 16:36









      JChatJChat

      1378




      1378




















          1 Answer
          1






          active

          oldest

          votes


















          3












          $begingroup$

          You can use the Kolmogorov-Smirnov Test. From Wikipedia




          In statistics, the Kolmogorov–Smirnov test (K–S test or KS test) is a
          nonparametric test of the equality of continuous, one-dimensional
          probability distributions that can be used to compare a sample with a
          reference probability distribution (one-sample K–S test), or to
          compare two samples (two-sample K–S test). It is named after Andrey
          Kolmogorov and Nikolai Smirnov.




          Good for us, there is already an implementation for this in Scipy



          You can use this dummy code to test it



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in range(103):
          test = stats.ks_2samp(df1.ix[col,], df2.ix[col,])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          I made the assumption that the columns that you want to compare are on the same index in both dataframes. If this is not true, you need to find another way. Maybe if they have the same name? You can do it like that.



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in df1:
          test = stats.ks_2samp(df1[col], df2[col])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          If the K-S statistic is small or the p-value is high, then we cannot reject the hypothesis that the distributions of the two samples are the same.



          Edit: I haven't tried it before, but maybe you can do something like that



          Boxplot



          from scipy import stats
          import numpy as np
          import pandas as pd
          import matplotlib.pyplot as plt

          #create 2 dataframes with random integers. I don't have data to simulate your case.

          df1 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))
          df2 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))

          #apply the Kolmogorov-Smirnov Test

          p_value = 0.05
          p_values = []
          for col in range(103):
          test = stats.ks_2samp(df1.iloc[col,], df2.iloc[col,])
          p_values.append(test[1])

          #create the box plot

          plt.boxplot(p_values)
          plt.title('Boxplot of p-values')
          plt.ylabel("p_values")
          plt.show()


          Boxplot



          Heatmap



          Another way is the heatmap.



          import matplotlib.patches as mpatches

          plt.rcParams["figure.figsize"] = 5,2
          x = range(1,104)
          y = np.array(p_values)
          fig, (ax,ax2) = plt.subplots(nrows=2, sharex=True)

          extent = [x[0]-(x[1]-x[0])/2., x[-1]+(x[1]-x[0])/2.,0,1]
          im = ax.imshow(y[np.newaxis,:], cmap="plasma", aspect="auto", extent=extent)
          ax.set_yticks([])
          ax.set_xlim(extent[0], extent[1])

          values = np.unique(np.round(y.ravel(),2))

          colors = [ im.cmap(im.norm(value)) for value in values]
          # create a patch (proxy artist) for every color
          patches = [ mpatches.Patch(color=colors[i], label="Level l".format(l=values[i]) ) for i in range(len(values)) ]
          # put those patched as legend-handles into the legend
          plt.legend(handles=patches, bbox_to_anchor=(1.05, 2.2), loc=2, borderaxespad=0. )

          ax2.plot(x,p_values)

          plt.tight_layout()
          plt.show()


          Heatmap



          Code for heatmap: stackoverflow






          share|improve this answer











          $endgroup$












          • $begingroup$
            Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
            $endgroup$
            – JChat
            Apr 1 at 11:46











          • $begingroup$
            Can you check the edited answer now?
            $endgroup$
            – Tasos
            Apr 2 at 6:47










          • $begingroup$
            Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
            $endgroup$
            – JChat
            Apr 2 at 7:51






          • 1




            $begingroup$
            Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
            $endgroup$
            – Tasos
            Apr 2 at 8:18










          • $begingroup$
            Thanks! :) It is a helpful answer!
            $endgroup$
            – JChat
            Apr 2 at 9:18











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48302%2fany-suitable-way-to-describe-the-distributions-of-2-pandas-dataframes-visually-g%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3












          $begingroup$

          You can use the Kolmogorov-Smirnov Test. From Wikipedia




          In statistics, the Kolmogorov–Smirnov test (K–S test or KS test) is a
          nonparametric test of the equality of continuous, one-dimensional
          probability distributions that can be used to compare a sample with a
          reference probability distribution (one-sample K–S test), or to
          compare two samples (two-sample K–S test). It is named after Andrey
          Kolmogorov and Nikolai Smirnov.




          Good for us, there is already an implementation for this in Scipy



          You can use this dummy code to test it



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in range(103):
          test = stats.ks_2samp(df1.ix[col,], df2.ix[col,])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          I made the assumption that the columns that you want to compare are on the same index in both dataframes. If this is not true, you need to find another way. Maybe if they have the same name? You can do it like that.



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in df1:
          test = stats.ks_2samp(df1[col], df2[col])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          If the K-S statistic is small or the p-value is high, then we cannot reject the hypothesis that the distributions of the two samples are the same.



          Edit: I haven't tried it before, but maybe you can do something like that



          Boxplot



          from scipy import stats
          import numpy as np
          import pandas as pd
          import matplotlib.pyplot as plt

          #create 2 dataframes with random integers. I don't have data to simulate your case.

          df1 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))
          df2 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))

          #apply the Kolmogorov-Smirnov Test

          p_value = 0.05
          p_values = []
          for col in range(103):
          test = stats.ks_2samp(df1.iloc[col,], df2.iloc[col,])
          p_values.append(test[1])

          #create the box plot

          plt.boxplot(p_values)
          plt.title('Boxplot of p-values')
          plt.ylabel("p_values")
          plt.show()


          Boxplot



          Heatmap



          Another way is the heatmap.



          import matplotlib.patches as mpatches

          plt.rcParams["figure.figsize"] = 5,2
          x = range(1,104)
          y = np.array(p_values)
          fig, (ax,ax2) = plt.subplots(nrows=2, sharex=True)

          extent = [x[0]-(x[1]-x[0])/2., x[-1]+(x[1]-x[0])/2.,0,1]
          im = ax.imshow(y[np.newaxis,:], cmap="plasma", aspect="auto", extent=extent)
          ax.set_yticks([])
          ax.set_xlim(extent[0], extent[1])

          values = np.unique(np.round(y.ravel(),2))

          colors = [ im.cmap(im.norm(value)) for value in values]
          # create a patch (proxy artist) for every color
          patches = [ mpatches.Patch(color=colors[i], label="Level l".format(l=values[i]) ) for i in range(len(values)) ]
          # put those patched as legend-handles into the legend
          plt.legend(handles=patches, bbox_to_anchor=(1.05, 2.2), loc=2, borderaxespad=0. )

          ax2.plot(x,p_values)

          plt.tight_layout()
          plt.show()


          Heatmap



          Code for heatmap: stackoverflow






          share|improve this answer











          $endgroup$












          • $begingroup$
            Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
            $endgroup$
            – JChat
            Apr 1 at 11:46











          • $begingroup$
            Can you check the edited answer now?
            $endgroup$
            – Tasos
            Apr 2 at 6:47










          • $begingroup$
            Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
            $endgroup$
            – JChat
            Apr 2 at 7:51






          • 1




            $begingroup$
            Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
            $endgroup$
            – Tasos
            Apr 2 at 8:18










          • $begingroup$
            Thanks! :) It is a helpful answer!
            $endgroup$
            – JChat
            Apr 2 at 9:18















          3












          $begingroup$

          You can use the Kolmogorov-Smirnov Test. From Wikipedia




          In statistics, the Kolmogorov–Smirnov test (K–S test or KS test) is a
          nonparametric test of the equality of continuous, one-dimensional
          probability distributions that can be used to compare a sample with a
          reference probability distribution (one-sample K–S test), or to
          compare two samples (two-sample K–S test). It is named after Andrey
          Kolmogorov and Nikolai Smirnov.




          Good for us, there is already an implementation for this in Scipy



          You can use this dummy code to test it



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in range(103):
          test = stats.ks_2samp(df1.ix[col,], df2.ix[col,])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          I made the assumption that the columns that you want to compare are on the same index in both dataframes. If this is not true, you need to find another way. Maybe if they have the same name? You can do it like that.



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in df1:
          test = stats.ks_2samp(df1[col], df2[col])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          If the K-S statistic is small or the p-value is high, then we cannot reject the hypothesis that the distributions of the two samples are the same.



          Edit: I haven't tried it before, but maybe you can do something like that



          Boxplot



          from scipy import stats
          import numpy as np
          import pandas as pd
          import matplotlib.pyplot as plt

          #create 2 dataframes with random integers. I don't have data to simulate your case.

          df1 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))
          df2 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))

          #apply the Kolmogorov-Smirnov Test

          p_value = 0.05
          p_values = []
          for col in range(103):
          test = stats.ks_2samp(df1.iloc[col,], df2.iloc[col,])
          p_values.append(test[1])

          #create the box plot

          plt.boxplot(p_values)
          plt.title('Boxplot of p-values')
          plt.ylabel("p_values")
          plt.show()


          Boxplot



          Heatmap



          Another way is the heatmap.



          import matplotlib.patches as mpatches

          plt.rcParams["figure.figsize"] = 5,2
          x = range(1,104)
          y = np.array(p_values)
          fig, (ax,ax2) = plt.subplots(nrows=2, sharex=True)

          extent = [x[0]-(x[1]-x[0])/2., x[-1]+(x[1]-x[0])/2.,0,1]
          im = ax.imshow(y[np.newaxis,:], cmap="plasma", aspect="auto", extent=extent)
          ax.set_yticks([])
          ax.set_xlim(extent[0], extent[1])

          values = np.unique(np.round(y.ravel(),2))

          colors = [ im.cmap(im.norm(value)) for value in values]
          # create a patch (proxy artist) for every color
          patches = [ mpatches.Patch(color=colors[i], label="Level l".format(l=values[i]) ) for i in range(len(values)) ]
          # put those patched as legend-handles into the legend
          plt.legend(handles=patches, bbox_to_anchor=(1.05, 2.2), loc=2, borderaxespad=0. )

          ax2.plot(x,p_values)

          plt.tight_layout()
          plt.show()


          Heatmap



          Code for heatmap: stackoverflow






          share|improve this answer











          $endgroup$












          • $begingroup$
            Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
            $endgroup$
            – JChat
            Apr 1 at 11:46











          • $begingroup$
            Can you check the edited answer now?
            $endgroup$
            – Tasos
            Apr 2 at 6:47










          • $begingroup$
            Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
            $endgroup$
            – JChat
            Apr 2 at 7:51






          • 1




            $begingroup$
            Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
            $endgroup$
            – Tasos
            Apr 2 at 8:18










          • $begingroup$
            Thanks! :) It is a helpful answer!
            $endgroup$
            – JChat
            Apr 2 at 9:18













          3












          3








          3





          $begingroup$

          You can use the Kolmogorov-Smirnov Test. From Wikipedia




          In statistics, the Kolmogorov–Smirnov test (K–S test or KS test) is a
          nonparametric test of the equality of continuous, one-dimensional
          probability distributions that can be used to compare a sample with a
          reference probability distribution (one-sample K–S test), or to
          compare two samples (two-sample K–S test). It is named after Andrey
          Kolmogorov and Nikolai Smirnov.




          Good for us, there is already an implementation for this in Scipy



          You can use this dummy code to test it



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in range(103):
          test = stats.ks_2samp(df1.ix[col,], df2.ix[col,])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          I made the assumption that the columns that you want to compare are on the same index in both dataframes. If this is not true, you need to find another way. Maybe if they have the same name? You can do it like that.



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in df1:
          test = stats.ks_2samp(df1[col], df2[col])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          If the K-S statistic is small or the p-value is high, then we cannot reject the hypothesis that the distributions of the two samples are the same.



          Edit: I haven't tried it before, but maybe you can do something like that



          Boxplot



          from scipy import stats
          import numpy as np
          import pandas as pd
          import matplotlib.pyplot as plt

          #create 2 dataframes with random integers. I don't have data to simulate your case.

          df1 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))
          df2 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))

          #apply the Kolmogorov-Smirnov Test

          p_value = 0.05
          p_values = []
          for col in range(103):
          test = stats.ks_2samp(df1.iloc[col,], df2.iloc[col,])
          p_values.append(test[1])

          #create the box plot

          plt.boxplot(p_values)
          plt.title('Boxplot of p-values')
          plt.ylabel("p_values")
          plt.show()


          Boxplot



          Heatmap



          Another way is the heatmap.



          import matplotlib.patches as mpatches

          plt.rcParams["figure.figsize"] = 5,2
          x = range(1,104)
          y = np.array(p_values)
          fig, (ax,ax2) = plt.subplots(nrows=2, sharex=True)

          extent = [x[0]-(x[1]-x[0])/2., x[-1]+(x[1]-x[0])/2.,0,1]
          im = ax.imshow(y[np.newaxis,:], cmap="plasma", aspect="auto", extent=extent)
          ax.set_yticks([])
          ax.set_xlim(extent[0], extent[1])

          values = np.unique(np.round(y.ravel(),2))

          colors = [ im.cmap(im.norm(value)) for value in values]
          # create a patch (proxy artist) for every color
          patches = [ mpatches.Patch(color=colors[i], label="Level l".format(l=values[i]) ) for i in range(len(values)) ]
          # put those patched as legend-handles into the legend
          plt.legend(handles=patches, bbox_to_anchor=(1.05, 2.2), loc=2, borderaxespad=0. )

          ax2.plot(x,p_values)

          plt.tight_layout()
          plt.show()


          Heatmap



          Code for heatmap: stackoverflow






          share|improve this answer











          $endgroup$



          You can use the Kolmogorov-Smirnov Test. From Wikipedia




          In statistics, the Kolmogorov–Smirnov test (K–S test or KS test) is a
          nonparametric test of the equality of continuous, one-dimensional
          probability distributions that can be used to compare a sample with a
          reference probability distribution (one-sample K–S test), or to
          compare two samples (two-sample K–S test). It is named after Andrey
          Kolmogorov and Nikolai Smirnov.




          Good for us, there is already an implementation for this in Scipy



          You can use this dummy code to test it



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in range(103):
          test = stats.ks_2samp(df1.ix[col,], df2.ix[col,])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          I made the assumption that the columns that you want to compare are on the same index in both dataframes. If this is not true, you need to find another way. Maybe if they have the same name? You can do it like that.



          from scipy import stats
          p_value = 0.05
          rejected = 0
          for col in df1:
          test = stats.ks_2samp(df1[col], df2[col])
          if test[1] < p_value:
          rejected += 1
          print("We rejected",rejected,"columns in total")


          If the K-S statistic is small or the p-value is high, then we cannot reject the hypothesis that the distributions of the two samples are the same.



          Edit: I haven't tried it before, but maybe you can do something like that



          Boxplot



          from scipy import stats
          import numpy as np
          import pandas as pd
          import matplotlib.pyplot as plt

          #create 2 dataframes with random integers. I don't have data to simulate your case.

          df1 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))
          df2 = pd.DataFrame(np.random.randint(0,100,size=(10000, 102)), columns=range(1,103))

          #apply the Kolmogorov-Smirnov Test

          p_value = 0.05
          p_values = []
          for col in range(103):
          test = stats.ks_2samp(df1.iloc[col,], df2.iloc[col,])
          p_values.append(test[1])

          #create the box plot

          plt.boxplot(p_values)
          plt.title('Boxplot of p-values')
          plt.ylabel("p_values")
          plt.show()


          Boxplot



          Heatmap



          Another way is the heatmap.



          import matplotlib.patches as mpatches

          plt.rcParams["figure.figsize"] = 5,2
          x = range(1,104)
          y = np.array(p_values)
          fig, (ax,ax2) = plt.subplots(nrows=2, sharex=True)

          extent = [x[0]-(x[1]-x[0])/2., x[-1]+(x[1]-x[0])/2.,0,1]
          im = ax.imshow(y[np.newaxis,:], cmap="plasma", aspect="auto", extent=extent)
          ax.set_yticks([])
          ax.set_xlim(extent[0], extent[1])

          values = np.unique(np.round(y.ravel(),2))

          colors = [ im.cmap(im.norm(value)) for value in values]
          # create a patch (proxy artist) for every color
          patches = [ mpatches.Patch(color=colors[i], label="Level l".format(l=values[i]) ) for i in range(len(values)) ]
          # put those patched as legend-handles into the legend
          plt.legend(handles=patches, bbox_to_anchor=(1.05, 2.2), loc=2, borderaxespad=0. )

          ax2.plot(x,p_values)

          plt.tight_layout()
          plt.show()


          Heatmap



          Code for heatmap: stackoverflow







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 2 at 8:17

























          answered Apr 1 at 6:09









          TasosTasos

          1,59011138




          1,59011138











          • $begingroup$
            Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
            $endgroup$
            – JChat
            Apr 1 at 11:46











          • $begingroup$
            Can you check the edited answer now?
            $endgroup$
            – Tasos
            Apr 2 at 6:47










          • $begingroup$
            Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
            $endgroup$
            – JChat
            Apr 2 at 7:51






          • 1




            $begingroup$
            Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
            $endgroup$
            – Tasos
            Apr 2 at 8:18










          • $begingroup$
            Thanks! :) It is a helpful answer!
            $endgroup$
            – JChat
            Apr 2 at 9:18
















          • $begingroup$
            Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
            $endgroup$
            – JChat
            Apr 1 at 11:46











          • $begingroup$
            Can you check the edited answer now?
            $endgroup$
            – Tasos
            Apr 2 at 6:47










          • $begingroup$
            Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
            $endgroup$
            – JChat
            Apr 2 at 7:51






          • 1




            $begingroup$
            Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
            $endgroup$
            – Tasos
            Apr 2 at 8:18










          • $begingroup$
            Thanks! :) It is a helpful answer!
            $endgroup$
            – JChat
            Apr 2 at 9:18















          $begingroup$
          Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
          $endgroup$
          – JChat
          Apr 1 at 11:46





          $begingroup$
          Thanks for the answer. Yes, the columns of both dataframes are having same name and indices. I wonder if there is a way to present this visually/graphically as I mentioned in the question and can you please add a sample code example for plotting this? Cheers
          $endgroup$
          – JChat
          Apr 1 at 11:46













          $begingroup$
          Can you check the edited answer now?
          $endgroup$
          – Tasos
          Apr 2 at 6:47




          $begingroup$
          Can you check the edited answer now?
          $endgroup$
          – Tasos
          Apr 2 at 6:47












          $begingroup$
          Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
          $endgroup$
          – JChat
          Apr 2 at 7:51




          $begingroup$
          Thanks for that. Is there a way to describe the colors in the heatmap using a legend or something?
          $endgroup$
          – JChat
          Apr 2 at 7:51




          1




          1




          $begingroup$
          Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
          $endgroup$
          – Tasos
          Apr 2 at 8:18




          $begingroup$
          Not the best implementation. Maybe you could try to group the values. But it's the best I can do it the short time :)
          $endgroup$
          – Tasos
          Apr 2 at 8:18












          $begingroup$
          Thanks! :) It is a helpful answer!
          $endgroup$
          – JChat
          Apr 2 at 9:18




          $begingroup$
          Thanks! :) It is a helpful answer!
          $endgroup$
          – JChat
          Apr 2 at 9:18

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48302%2fany-suitable-way-to-describe-the-distributions-of-2-pandas-dataframes-visually-g%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

          Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High