Package: a-pandas-ex-intersection-difference
Computes the intersection/symmetric difference of n DataFrames/SeriesInstallationpipinstalla-pandas-ex-intersection-differenceUsagefroma_pandas_ex_intersection_differenceimportpd_add_setpd_add_set()importpandasaspdTHE CODE ABOVE WILL ADD SOME METHODS TO! YOU CAN USE PANDAS LIKE YOU DID BEFORE, BUT YOU WILL HAVE A COUPLE OF METHODS MORE:pandas.DataFrame.ds_set_intersections/ pandas.Series.ds_set_intersectionspandas.DataFrame.ds_set_symmetric_difference/ pandas.Series.ds_set_symmetric_differencepandas.DataFrame.ds_set_union/pandas.Series.ds_set_unionpandas.DataFrame.ds_value_counts_to_column/ pandas.Series.ds_value_counts_to_columnpandas.DataFrame.ds_set_intersections/ pandas.Series.ds_set_intersections#Computes the intersection of n DataFrames/Series#Exampledf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")#Let's create some DataFrames with random data from dfdf1=df.sample(len(df)-len(df)//2).copy()df2=df.sample(len(df)-len(df)//2).copy()df3=df.sample(len(df)-len(df)//2).copy()df4=df.sample(len(df)-len(df)//2).copy()df5=df.sample(len(df)-len(df)//2).copy()df1.ds_set_intersections(df2)#Comparing 2 DataFramesOut[14]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin0180226.25001...1SfemaleNaN10506108.90000...1CmaleC652038673.50000...0SmaleNaN3062114.45420...1CmaleNaN4127319.50001...0SfemaleNaN.............................439024012.27500...0SmaleNaN440023510.50000...0SmaleNaN4411269153.46251...0SfemaleC1254420394113.27501...1CfemaleD36443040012.65001...0SfemaleNaN[444rowsx12columns]df1.ds_set_intersections(df2,df3)#Comparing 3 DataFramesOut[15]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin00506108.90000...1CmaleC651148012.28751...0SfemaleNaN2158130.00001...1SfemaleNaN3144719.50001...0SfemaleNaN401616.00001...0SfemaleNaN.............................340215414.50000...0SmaleNaN34106687.77500...0SmaleNaN342070226.28751...0SmaleE243430610153.46251...0SfemaleC125344045030.50001...0SmaleC104[345rowsx12columns]df1.ds_set_intersections(df2,df3,df4)#Comparing 4 DataFramesOut[16]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin00506108.90000...1CmaleC651158130.00001...1SfemaleNaN202839.50000...0SmaleNaN3048829.70000...0CmaleB3740610153.46251...0SfemaleC125.............................2270238.02921...0QfemaleNaN228161939.00001...2SfemaleF4229247327.75001...1SfemaleNaN230025326.55000...0SmaleC87231061816.10000...1SfemaleNaN[232rowsx12columns]df1.ds_set_intersections(df2,df3,df4,df5)#Comparing 5 DataFramesOut[17]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin00506108.90000...1CmaleC651158130.00001...1SfemaleNaN211729.12500...4QmaleNaN325927.75001...1SfemaleNaN4046338.50000...0SmaleE63.............................140216620.52501...0SmaleNaN14107057.85420...1SmaleNaN14215139.68750...4SmaleNaN14308337.22920...0CmaleNaN144215414.50000...0SmaleNaN[145rowsx12columns]pandas.DataFrame.ds_set_symmetric_difference/ pandas.Series.ds_set_symmetric_difference#Computes the symmetric difference of n DataFrames/Series#Exampledf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")#Let's create some DataFrames with random data from dfdf1=df.sample(len(df)-len(df)//2).copy()df2=df.sample(len(df)-len(df)//2).copy()df3=df.sample(len(df)-len(df)//2).copy()df4=df.sample(len(df)-len(df)//2).copy()df5=df.sample(len(df)-len(df)//2).copy()df1.ds_set_symmetric_difference(df2)#Comparing 2 DataFramesOut[18]:ParchPassengerIdFare...EmbarkedSexCabin005677.8958...SmaleNaN10468.0500...SmaleNaN22342263.0000...SfemaleC23C25C27308458.6625...SmaleNaN4017.2500...SmaleNaN.......................219086513.0000...SmaleNaN220563939.6875...SfemaleNaN2210307.8958...SmaleNaN222033228.5000...SmaleC124223088410.5000...SmaleNaN[448rowsx12columns]df1.ds_set_symmetric_difference(df2,df3)#Comparing 3 DataFramesOut[19]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin005677.89580...0SmaleNaN10468.05000...0SmaleNaN208458.66250...0SmaleNaN301427.75001...0SfemaleNaN4057914.45830...1CfemaleNaN.............................10604308.05001...0SmaleE10107136314.45420...0CfemaleNaN108153126.00001...1SfemaleNaN109074813.00001...0SfemaleNaN11008767.22501...0CfemaleNaN[339rowsx12columns]df1.ds_set_symmetric_difference(df2,df3,df4)#Comparing 4 DataFramesOut[20]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin005677.89580...0SmaleNaN10468.05000...0SmaleNaN201427.75001...0SfemaleNaN3057914.45830...1CfemaleNaN4036515.50000...1QmaleNaN.............................392551110.88331...0CmaleC704001918.00000...1SfemaleNaN4106158.05000...0SmaleNaN4202047.22500...0CmaleNaN43137521.07500...3SfemaleNaN[204rowsx12columns]df1.ds_set_symmetric_difference(df2,df3,df4,df5)#Comparing 5 DataFramesOut[21]:ParchPassengerIdFareSurvived...SibSpEmbarkedSexCabin005677.89580...0SmaleNaN1057914.45830...1CfemaleNaN2036515.50000...1QmaleNaN3064456.49581...0SmaleNaN4070826.28751...0SmaleE24.............................25034313.00000...0SmaleNaN26065673.50000...2SmaleNaN2704077.75000...0SmaleNaN2803017.75001...0QfemaleNaN2908196.45000...0SmaleNaN[125rowsx12columns]Parametersargs:Union[pd.Series,pd.DataFrame]DataFramesorSeries,howmanyyouwantaccept_df_with_different_columns:bool=TrueLet's say you have one DataFrame whose columns are:  [Parch,  PassengerId, Fare, Survived, SibSp,Embarked,  Sex, Cabin]Ifyouwanttocompareitto:[Flight,Fare,Survived,SibSp,Embarked,Sex,Cabin]Itwon't work, unless you pass accept_df_with_different_columns=TrueOnlythecolumnsthatareinalldataframeswillbecomparedReturnspd.DataFramepandas.DataFrame.ds_set_union/pandas.Series.ds_set_uniondf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")#Let's create some DataFrames with random data from dfdf1=df.sample(len(df)-len(df)//2).copy()df2=df.sample(len(df)-len(df)//2).copy()df3=df.sample(len(df)-len(df)//2).copy()df4=df.sample(len(df)-len(df)//2).copy()df5=df.sample(len(df)-len(df)//2).copy()df1[['PassengerId','Survived','Name']].ds_set_union(df2[['Pclass','Cabin','Name']])Out[17]:Name0Carbines,Mr.William1Sundman,Mr.JohanJulian2Dimic,Mr.Jovan3Harder,Mr.GeorgeAchilles4Rice,Master.Eugene.....887Carlsson,Mr.AugustSigfrid888Hoyt,Mr.FrederickMaxfield889Somerton,Mr.FrancisWilliam890Francatelli,Miss.LauraMabel891Thayer,Mrs.JohnBorland(MarianLongstrethM...#If, for whatever reason, you don't want to use pd.concat(), you can use this method.#Don't use this method if you can use pd.concatParametersargs:Union[pd.Series,pd.DataFrame]DataFramesorSeries,howmanyyouwantaccept_df_with_different_columns:bool=TrueLet's say you have one DataFrame whose columns are:  [Parch,  PassengerId, Fare, Survived, SibSp,Embarked,  Sex, Cabin]Ifyouwanttocompareitto:[Flight,Fare,Survived,SibSp,Embarked,Sex,Cabin]Itwon't work, unless you pass accept_df_with_different_columns=TrueOnlythecolumnsthatareinalldataframeswillbecomparedReturnspd.DataFramepandas.DataFrame.ds_value_counts_to_column/ pandas.Series.ds_value_counts_to_columndf=pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv")df2.Sex.ds_value_counts_to_column()PassengerIdSurvivedPclass...FareCabinEmbarked50450511...86.5000B79S78178211...57.0000B20S85585613...9.3500NaNS55255303...7.8292NaNQ77777813...12.4750NaNS.......................75675703...7.7958NaNS22422511...90.0000C93S48848903...8.0500NaNS30931011...56.9292E36C58158211...110.8833C68C[446rowsx12columns]df2.Sex.ds_value_counts_to_column()Out[22]:01521152215232944152...441294442294443294444152445152Name:0,Length:446,dtype:int64Thismethodcouldalsobeuseful,whenyouarecomparingDataFrames,sinceitcountsthedifferentvaluesinaSeriesandreturnsaDataFramethatyoucanmergewithyouroriginalDataFrameParametersdf:pd.SeriesReturnspd.DataFrame