0

So I need to manipulate some data in a DB. I'm executing a Select statement that grabs me data that looks like this:

UserID | Value1 | Value2 | ...  
123    | A      | ...
444    | D      | ...
123    | C      | ...
666    | R      | ...  

What I want to do, is create a report with this data. What you see is the result of a join on a few tables.

I'm new to Python, but not new to DB's. I know in C# I can get back a List of objects representing each row. I'm sure Python does something similiar. However, then I'd have to go in and maybe hash each record and then store the values in a List or something so I don't create a report that says

123, A, ...  (report 1)   
123, C, ...  (report 2).   

I want to just grab 123, A/C, ... (the '...' data is different as well). And create 1 report.

In SQL I can't really do that. I guess this is more just parsing through/grouping data in Python. I know there's linq as well in C# for something like this.

This is with Django for what it's worth.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
Future44
  • 11
  • 3
  • Your question is not clear. What exact output are you looking for? Also, since this is Django, please show the models. – Daniel Roseman Jan 12 '18 at 07:36
  • 1
    @Future44 why don't you first start your Django project, write a first draft of your models, add some test data and try and find out by yourself (using the doc) how to get those results with either the ORM or raw SQL - and then post if and when you _really_ have a problem ? – bruno desthuilliers Jan 12 '18 at 08:00
  • 1
    @Future44 The same than bruno-desthuilliers, but also try not to use swear words when you are asking for help. – osmay88 Jan 12 '18 at 08:04

1 Answers1

0

hypothetically, this post may contain the information that you are looking for:

Pandas groupby: How to get a union of strings

in other words, you could try something like

DB.groupby('UserID')['Value1'].apply(list)
api55
  • 11,070
  • 4
  • 41
  • 57
MissBleu
  • 175
  • 2
  • 15
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/18496733) – Akos Nagy Jan 12 '18 at 08:41
  • Thanks for the tip! I will edit my post to reflect your suggestion – MissBleu Jan 12 '18 at 08:48