[Tutor] R: Re: Create a pivot table (Peter Otten)

2016-05-20 Thread jarod_v6--- via Tutor
Thanks s much for  the help. I want to obtain table like this:


>csv.writer(sys.stdout, delimiter="\t").writerows(table)
>A100D33 D34 D35 D36 D37 D38 D39
>A   5 0 ...
>B   2 2  ...
>C  0  ..
>
I have tried the pandas way but unfortunately there is many duplicates . So 
Now I move to create a new file using dictionary  and  a file with this format.

('A', A100') 5
('B', 'A100) 2

I just wondering if there is a pythonic way to do this. I don't want to use 
another software if I can

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Create a pivot table

2016-05-20 Thread Peter Otten
jarod_v6--- via Tutor wrote:

Please address your posts to the whole list, not me specifically. I might 
read them all the same. 

Thank you.

> Thanks s much for  the help. I want to obtain table like this:
> 
> 
>>csv.writer(sys.stdout, delimiter="\t").writerows(table)
>>A100D33 D34 D35 D36 D37 D38 D39
>>A   5 0 ...
>>B   2 2  ...
>>C  0  ..
>>
> I have tried the pandas way but unfortunately there is many duplicates .

Please show your code in a small self-contained example, 
the output it produces, and what exact output you want instead.
Then one of us (not necessarily me) might be able to help you fix it.

> So
> Now I move to create a new file using dictionary  and  a file with this
> format.
> 
> ('A', A100') 5
> ('B', 'A100) 2
> 
> I just wondering if there is a pythonic way to do this. 

"Pythonic" is elegant idiomatic Python. At this stage I'd settle for 
anything that works. Just saying...

> I don't want to use another software if I can

$ cat pivot_demo2.py
import csv
import operator
import sys
from pivot import pivot

data = {
("A", "A100"): 5,
("B", "A100"): 2,
("B", "D33"): 2,
}

table = pivot(
data,
operator.itemgetter(1),
operator.itemgetter(0),
lambda k, data=data: data[k],
empty=0)
csv.writer(sys.stdout, delimiter="\t").writerows(table)
$ python3 pivot_demo2.py
A100D33
A   5   0
B   2   2
$ 


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Create a pivot table

2016-05-20 Thread Michael Selik
On Fri, May 20, 2016 at 8:42 AM Peter Otten <__pete...@web.de> wrote:

> jarod_v6--- via Tutor wrote:
> > I have tried the pandas way but unfortunately there is many duplicates .
>
> Please show your code in a small self-contained example,
> the output it produces, and what exact output you want instead.
> Then one of us (not necessarily me) might be able to help you fix it.
>

I haven't seen an Pandas code, yet. What's the error message and traceback?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] genfromtxt and dtype to convert data to correct format

2016-05-20 Thread Ek Esawi
Thanks again Alan for your help and patience. Your earlier suggestion
works; i just now realized that the output was indeed correct. Thanks
again--EK
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] R: Re: Create a pivot table (Peter Otten)

2016-05-20 Thread Michael Selik
On Fri, May 20, 2016 at 7:16 AM jarod_v6--- via Tutor 
wrote:

> Thanks s much for  the help. I want to obtain table like this:
>
>
> >csv.writer(sys.stdout, delimiter="\t").writerows(table)
> >A100D33 D34 D35 D36 D37 D38 D39
> >A   5 0 ...
> >B   2 2  ...
> >C  0  ..
> >
> I have tried the pandas way but unfortunately there is many duplicates.
>

If pandas is raising an error, it's possible a "pivot" is not what you
want. What's the code you tried? What's the error message?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor