3

I have two CSV files, the first like so:

Book1:

ID,TITLE,SUBJECT
0001,BLAH,OIL
0002,BLAH,HAMSTER
0003,BLAH,HAMSTER
0004,BLAH,PLANETS
0005,BLAH,JELLO
0006,BLAH,OIL
0007,BLAH,HAMSTER
0008,BLAH,JELLO
0009,BLAH,JELLO
0010,BLAH,HAMSTER
0011,BLAH,OIL
0012,BLAH,OIL
0013,BLAH,OIL
0014,BLAH,JELLO
0015,BLAH,JELLO
0016,BLAH,HAMSTER
0017,BLAH,PLANETS
0018,BLAH,PLANETS
0019,BLAH,HAMSTER
0020,BLAH,HAMSTER

And then a second CSV with items associated with the first list, with ID being the common attribute between the two.

Book2:

ID,ITEM
0001,PURSE
0001,STEAM
0001,SEASHELL
0002,TRUMPET
0002,TRAMPOLINE
0003,PURSE
0003,DOLPHIN
0003,ENVELOPE
0004,SEASHELL
0004,SERPENT
0004,TRUMPET
0005,CAR
0005,NOODLE
0006,CANNONBALL
0006,NOODLE
0006,ORANGE
0006,SEASHELL
0007,CREAM
0007,CANNONBALL
0007,GUM
0008,SERPENT
0008,NOODLE
0008,CAR
0009,CANNONBALL
0009,SERPENT
0009,GRAPE
0010,SERPENT
0010,CAR
0010,TAPE
0011,CANNONBALL
0011,GRAPE
0012,ORANGE
0012,GUM
0012,SEASHELL
0013,NOODLE
0013,CAR
0014,STICK
0014,ORANGE
0015,GUN
0015,GRAPE
0015,STICK
0016,BASEBALL
0016,SEASHELL
0017,CANNONBALL
0017,ORANGE
0017,TRUMPET
0018,GUM
0018,STICK
0018,GRAPE
0018,CAR
0019,CANNONBALL
0019,TRUMPET
0019,ORANGE
0020,TRUMPET
0020,CHERRY
0020,ORANGE
0020,GUM

The real datasets are millions of records, so I'm sorry in advance for my simple example.

The problem I need to solve is getting the data merged and collated in a way where I can see which item groupings most commonly appear together on the same ID. (e.g. GRAPE,GUM,SEASHELL appear together 340 times, ORANGE and STICK 89 times, etc...)

Then I need to see if there is any change/deviation to the general results in common appearance when grouped by SUBJECT.

Tools I'm familiar with are Excel and SQL, but I also have PowerBI and Alteryx at my disposal.

Full disclosure: Not homework, or work, but a volunteer project, thus my unfamiliarity with this kind of data manipulation.

Thanks in advance.

A New Guy
  • 31
  • 1
  • After merging, do you expect three rows with ID 1: Blah and Oil matched with each of Purse, Stream, and Seashell? If so in Alteryx it would be a simple join on ID, then an aggregation (Summary tool) grouping on the other three and counting distinct IDs for each group. Hope that helps. – johnjps111 Apr 26 '18 at 02:33
  • PowerQuery in Excel can do merging and summarizing nicely. Can you give an example of what you want your output to look like? – Alexis Olson Apr 26 '18 at 02:42

4 Answers4

1

An Alteryx solution:

  1. Drag the two .csv files onto your canvas (seen as book1.csv and book2.csv in my picture; Alteryx will create "Input" tools for you.
  2. Drag a "Join" tool on and connect the two .csv files to its inputs; select "ID" as the join field; unselect the "Right_ID" as output since it's merely a duplicate of "ID"
  3. Drag a "Summary" tool on and connect the Join tool's output to the Summary tool's input; select all three of the outputs and add as a "group by"... then add the ID column with a "count"
  4. Drag a browse tool on and connect the summary's output to the browse tool's input.
  5. run the workflow

After all that, click on the browse tool and you should see what is seen in my screenshot: (which is showing just the first ten rows of output):

enter image description here

johnjps111
  • 1,060
  • 8
  • 21
0

+1 for taking on a volunteer project - I think anyone who knows data can have a big impact in support of their favourite group or cause.

I would just pull the 2 files into Power BI as 2 separate tables (Get Data / From File). Create a relationship between the 2 tables based on ID (it might get auto-generated). It should be one to many.

Then I would add a Calculated Column to the Book1 table to Concatenate the related ITEM values, eg.

Items =
CALCULATE (
    CONCATENATEX (
        DISTINCT ( 'Book2'[ITEM] ),
        'Book2'[ITEM],
        ", ",
        'Book2'[ITEM], ASC
    )
)

Now you can use that Items field in visuals (e.g. a Table), along with Count of ID to get the frequency.

Adding Subject to a copy of the table (e.g. to the Columns well of a Matrix) will produce your grouped scenario, or you could add a Subject Slicer.

As you will be comparing subsets of varying size, I would change Count of ID to Show value as - % of grand total.

Mike Honey
  • 13,594
  • 1
  • 21
  • 34
0

Little different solution using Alteryx.

With this dataset, there are very few repeating 3 or 4 item groups. You can do the two item affinity analysis and get a probability of 3 or 4 item groups, or you can count the 3 and 4 item groups individually. I believe what you want is the latter as your probability of getting grapes with oranges may be altered by whether you have bananas in the cart or not.

Anyway, I did not join in the subject until after finding all of my combinations. I found all the combinations by taking the Cartesian join of two, then three, then four of the original set. I then removed all duplicates by ensuring items were always in alphabetical order in each row. I then counted occurrences of each combination. More joins can be added in the same pattern to count groups of 5,6,7...

Once you have the counts of occurrences, then I would join back with the subjects and perform this analysis on each group and compare to the overall results.

Affinity analysis using Alteryx

  • I'm supposed to disclose that I work for Alteryx.
Ben
  • 126
  • 4
0

first of all if you are using windows just navigate to the directory which contains the CSV and write the following command:

copy pattern newfileName.csv
#example 
copy *.csv merged.csv

now you created one csv file, the file is too large now you can't process it once, depending on your programming language you can use appropriate way, for python you can use generators to process line by line, or pandas you can read chunk by chunk it will be easy.

I hope this help you.

Ahmed Ghazey
  • 460
  • 1
  • 8
  • 21