Get common values in several columns of a dataframe?

0

I have a table with numeric values and I would like to get the values in common in all columns (intersection) and the unique values of each using Python.

    Position_a  Position_b  Position_c  Position_d  Position_e  Position_f
0   45794939.0  45794939.0  45794939    45794939.0  45794939    45794939.0
1   45794975.0  45794975.0  45794975    45794975.0  45794975    45794975.0
2   45794983.0  45794983.0  45794983    45794983.0  45794983    45794983.0
3   45794988.0  45794988.0  45794988    45794988.0  45794988    45794988.0
4   45795006.0  45795006.0  45795006    45795006.0  45795006    45795006.0
    
asked by anonymous 08.06.2017 / 14:06

1 answer

0

Your example is a bit strange, since all rows are present in all columns, but perhaps the following method to count occurrences will help you.

    import pandas as pd
    import numpy as np

    data = {'Position_a': [45794975, 45794983, 45794988, 45795006, np.NaN],
            'Position_b': [45794939, 45794975, 45794983, 45794988, 45795006],
            'Position_c': [45794939, 45794975, 45794983, 45794988, 45795006],
            'Position_d': [45794939, 45794975, 45794983, 45794988,np.NaN],
            'Position_e': [45794939, 45794975, 45794983, 45795006, np.NaN],
            'Position_f': [45794939, 45794975, 45794983, 45794988, 45795006]
            }

    df = pd.DataFrame.from_dict(data)

    print(df)

    tidydf = pd.melt(df)

    tidydf.pivot_table(index = ['value'], columns = ['variable'], aggfunc = len, fill_value = 0)
    
22.06.2017 / 00:10