Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
What were you hoping to get from ``df[0]``?
When you say it "yields nothing" do you mean it raised an error? What was
the error message?

Have you tried a Google search for "pandas set index"?
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html

On Fri, May 13, 2016 at 11:18 PM David Shi  wrote:

> Hello, Michael,
>
> I tried to discover the problem.
>
> df[0]   yields nothing
> df[1]  yields nothing
> df[2] yields nothing
>
> However, df[3] gives the following:
>
> sid
> -9223372036854775808  NaN
>  1  133738.70
>  4  295256.11
>  5  137733.09
>  6  409413.58
>  8  269600.97
>  9   12852.94
>
>
> Can we split this back to normal?  or turn it into a dictionary, so that I 
> can put values back properly.
>
>
> I like to use sid as index, some way.
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 22:58, Michael Selik 
> wrote:
>
>
> What have code you tried? What error message are you receiving?
>
> On Fri, May 13, 2016, 5:54 PM David Shi  wrote:
>
> Hello, Michael,
>
> How to convert a float type column into an integer or label or string type?
>
>
> On Friday, 13 May 2016, 22:02, Michael Selik 
> wrote:
>
>
> To clarify that you're specifying the index as a label, use df.iloc
>
> >>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))
> >>> df
>X
> a  0
> b  1
> c  2
> d  3
> >>> df.loc['a']
> X0
> Name: a, dtype: int64
> >>> df.iloc[0]
> X0
> Name: a, dtype: int64
>
> On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:
>
> Dear Michael,
>
> To avoid complication, I only groupby using one column.
>
> It is OK now.  But, how to refer to new row index?  How do I use floating
> index?
>
> Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0,
>   17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 
> 27.0,
>   28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 
> 38.0,
>   39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 
> 50.0,
>   51.0, 53.0, 54.0, 55.0, 56.0],
>  dtype='float64', name=u'StateFIPS')
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:43, Michael Selik 
> wrote:
>
>
> Here's an example.
>
> >>> import pandas as pd
> >>> df = pd.DataFrame({'group': list('AB') * 2, 'data': range(4)},
> index=list('wxyz'))
> >>> df
>data group
> w 0 A
> x 1 B
> y 2 A
> z 3 B
> >>> df = df.reset_index()
> >>> df
>   index  data group
> 0 w 0 A
> 1 x 1 B
> 2 y 2 A
> 3 z 3 B
> >>> df.groupby('group').max()
>   index  data
> group
> A y 2
> B z 3
>
> If that doesn't help, you'll need to explain what you're trying to
> accomplish in detail -- what variables you started with, what
> transformations you want to do, and what variables you hope to have when
> finished.
>
> On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:
>
> Hello, Michael,
>
> I changed groupby with one column.
>
> The index is different.
>
> Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
>   u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
>   u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
>   u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
>   u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
>   u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
>   u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
>   u'WY'],
>   dtype='object', name=0)
>
>
> How to use this index?
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:19, David Shi  wrote:
>
>
> Hello, Michael,
>
> I typed in df.index
>
> I got the following
>
> MultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 
> 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 
> 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 54.0, 55.0, 
> 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', u'FL', u'GA', 
> u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', u'ME', u'MI', 
> u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', u'NM', u'NV', 
> u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', u'TN', 
> u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
>labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
> 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
> 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0,

Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
This is very weird.
55 145340.20
 56 25.43
Name: 3, dtype: float64
It looks like two columns, but it shows one single object.
Any clue? 

On Saturday, 14 May 2016, 4:15, David Shi  wrote:
 

 Hello, Michael,
I tried to discover the problem.
df[0]   yields nothingdf[1]  yields nothingdf[2] yields nothing
However, df[3] gives the following:sid
-9223372036854775808  NaN
 1  133738.70
 4  295256.11
 5  137733.09
 6  409413.58
 8  269600.97
 9   12852.94
Can we split this back to normal?  or turn it into a dictionary, so that I can 
put values back properly.
I like to use sid as index, some way.
Regards.
David 

On Friday, 13 May 2016, 22:58, Michael Selik  
wrote:
 

 What have code you tried? What error message are you receiving?
On Fri, May 13, 2016, 5:54 PM David Shi  wrote:

Hello, Michael,
How to convert a float type column into an integer or label or string type? 

On Friday, 13 May 2016, 22:02, Michael Selik  
wrote:
 

 To clarify that you're specifying the index as a label, use df.iloc
    >>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))    >>> df       
X    a  0    b  1    c  2    d  3    >>> df.loc['a']    X    0    Name: a, 
dtype: int64    >>> df.iloc[0]    X    0    Name: a, dtype: int64
On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:

Dear Michael,
To avoid complication, I only groupby using one column.
It is OK now.  But, how to refer to new row index?  How do I use floating index?
Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 16.0,
  17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0,
  28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0,
  39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0,
  51.0, 53.0, 54.0, 55.0, 56.0],
 dtype='float64', name=u'StateFIPS')
Regards.
David 

On Friday, 13 May 2016, 21:43, Michael Selik  
wrote:
 

 Here's an example.
    >>> import pandas as pd    >>> df = pd.DataFrame({'group': list('AB') * 2, 
'data': range(4)}, index=list('wxyz'))    >>> df       data group    w     0    
 A    x     1     B    y     2     A    z     3     B    >>> df = 
df.reset_index()    >>> df      index  data group    0     w     0     A    1   
  x     1     B    2     y     2     A    3     z     3     B    >>> 
df.groupby('group').max()          index  data    group    A         y     2    
B         z     3
If that doesn't help, you'll need to explain what you're trying to accomplish 
in detail -- what variables you started with, what transformations you want to 
do, and what variables you hope to have when finished.
On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:

Hello, Michael,
I changed groupby with one column.
The index is different.
Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
  u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
  u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
  u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
  u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
  u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
  u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
  u'WY'],
  dtype='object', name=0)
How to use this index?
Regards.
David 

On Friday, 13 May 2016, 21:19, David Shi  wrote:
 

 Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 47, 49]],
   names=[u'StateFIPS', 0])Regards.
David 

On Friday, 13 May 2016, 21:11, David Shi  wrote:
 

 Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset 

Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
I do not understand this.
I tried list =df[3]
it worked.  But, it does not behave like a list.
list[0] nothinglist[1] a valuelist[2] nothing
list[4] a value
It behaves like a dictionary. 

On Saturday, 14 May 2016, 4:27, David Shi  wrote:
 

 Hello, Michael,
This is very weird.
55 145340.20
 56 25.43
Name: 3, dtype: float64
It looks like two columns, but it shows one single object.
Any clue? 

On Saturday, 14 May 2016, 4:15, David Shi  wrote:
 

 Hello, Michael,
I tried to discover the problem.
df[0]   yields nothingdf[1]  yields nothingdf[2] yields nothing
However, df[3] gives the following:sid
-9223372036854775808  NaN
 1  133738.70
 4  295256.11
 5  137733.09
 6  409413.58
 8  269600.97
 9   12852.94
Can we split this back to normal?  or turn it into a dictionary, so that I can 
put values back properly.
I like to use sid as index, some way.
Regards.
David 

On Friday, 13 May 2016, 22:58, Michael Selik  
wrote:
 

 What have code you tried? What error message are you receiving?
On Fri, May 13, 2016, 5:54 PM David Shi  wrote:

Hello, Michael,
How to convert a float type column into an integer or label or string type? 

On Friday, 13 May 2016, 22:02, Michael Selik  
wrote:
 

 To clarify that you're specifying the index as a label, use df.iloc
    >>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))    >>> df       
X    a  0    b  1    c  2    d  3    >>> df.loc['a']    X    0    Name: a, 
dtype: int64    >>> df.iloc[0]    X    0    Name: a, dtype: int64
On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:

Dear Michael,
To avoid complication, I only groupby using one column.
It is OK now.  But, how to refer to new row index?  How do I use floating index?
Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 16.0,
  17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0,
  28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0,
  39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0,
  51.0, 53.0, 54.0, 55.0, 56.0],
 dtype='float64', name=u'StateFIPS')
Regards.
David 

On Friday, 13 May 2016, 21:43, Michael Selik  
wrote:
 

 Here's an example.
    >>> import pandas as pd    >>> df = pd.DataFrame({'group': list('AB') * 2, 
'data': range(4)}, index=list('wxyz'))    >>> df       data group    w     0    
 A    x     1     B    y     2     A    z     3     B    >>> df = 
df.reset_index()    >>> df      index  data group    0     w     0     A    1   
  x     1     B    2     y     2     A    3     z     3     B    >>> 
df.groupby('group').max()          index  data    group    A         y     2    
B         z     3
If that doesn't help, you'll need to explain what you're trying to accomplish 
in detail -- what variables you started with, what transformations you want to 
do, and what variables you hope to have when finished.
On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:

Hello, Michael,
I changed groupby with one column.
The index is different.
Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
  u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
  u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
  u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
  u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
  u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
  u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
  u'WY'],
  dtype='object', name=0)
How to use this index?
Regards.
David 

On Friday, 13 May 2016, 21:19, David Shi  wrote:
 

 Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41

Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
I tried to discover the problem.
df[0]   yields nothingdf[1]  yields nothingdf[2] yields nothing
However, df[3] gives the following:sid
-9223372036854775808  NaN
 1  133738.70
 4  295256.11
 5  137733.09
 6  409413.58
 8  269600.97
 9   12852.94
Can we split this back to normal?  or turn it into a dictionary, so that I can 
put values back properly.
I like to use sid as index, some way.
Regards.
David 

On Friday, 13 May 2016, 22:58, Michael Selik  
wrote:
 

 What have code you tried? What error message are you receiving?
On Fri, May 13, 2016, 5:54 PM David Shi  wrote:

Hello, Michael,
How to convert a float type column into an integer or label or string type? 

On Friday, 13 May 2016, 22:02, Michael Selik  
wrote:
 

 To clarify that you're specifying the index as a label, use df.iloc
    >>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))    >>> df       
X    a  0    b  1    c  2    d  3    >>> df.loc['a']    X    0    Name: a, 
dtype: int64    >>> df.iloc[0]    X    0    Name: a, dtype: int64
On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:

Dear Michael,
To avoid complication, I only groupby using one column.
It is OK now.  But, how to refer to new row index?  How do I use floating index?
Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 16.0,
  17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0,
  28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0,
  39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0,
  51.0, 53.0, 54.0, 55.0, 56.0],
 dtype='float64', name=u'StateFIPS')
Regards.
David 

On Friday, 13 May 2016, 21:43, Michael Selik  
wrote:
 

 Here's an example.
    >>> import pandas as pd    >>> df = pd.DataFrame({'group': list('AB') * 2, 
'data': range(4)}, index=list('wxyz'))    >>> df       data group    w     0    
 A    x     1     B    y     2     A    z     3     B    >>> df = 
df.reset_index()    >>> df      index  data group    0     w     0     A    1   
  x     1     B    2     y     2     A    3     z     3     B    >>> 
df.groupby('group').max()          index  data    group    A         y     2    
B         z     3
If that doesn't help, you'll need to explain what you're trying to accomplish 
in detail -- what variables you started with, what transformations you want to 
do, and what variables you hope to have when finished.
On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:

Hello, Michael,
I changed groupby with one column.
The index is different.
Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
  u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
  u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
  u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
  u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
  u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
  u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
  u'WY'],
  dtype='object', name=0)
How to use this index?
Regards.
David 

On Friday, 13 May 2016, 21:19, David Shi  wrote:
 

 Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 47, 49]],
   names=[u'StateFIPS', 0])Regards.
David 

On Friday, 13 May 2016, 21:11, David Shi  wrote:
 

 Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset index after grouping and various operations is of interest.
How to type in a command to find out its current dataframe?
Regards.
David 

On Friday, 13 May 2016, 20:58, Michael Selik  
wrote:
 

 Just in case I misunderstood, why don't you make a little

Re: Distinction between “class” and “type”

2016-05-13 Thread Steven D'Aprano
On Fri, 13 May 2016 03:07 pm, Ben Finney wrote:

> Howdy all,
> 
> Ever since Python's much-celebrated Grand Unification of classes and
> types, I have used those terms interchangeably: every class is a type,
> and every type is a class.
> 
> That may be an unwise conflation. With the recent rise of optional type
> annotation in Python 3, more people are speaking about the important
> distinction between a class and a type.
[...]
> As a Bear of Little Brain, this leaves me clueless. What is the
> distinction Guido alludes to, and how are Python classes not also types?
> 
> And why is this distinction important, and who moved my cheesecake?

You're not alone. Unfortunately, this confusion is endemic in IT and on the
internet. People use types all the time, but without understanding that
there are (at least) two related but distinct meanings for the word.

Even though it isn't specifically about this distinction, you should start
by reading this essay about the distinction between static and dynamic
typing here:

https://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/

Then you should read Guido's PEP 483 on "gradual typing":

https://www.python.org/dev/peps/pep-0483/


And this answer on Stackoverflow:

http://stackoverflow.com/a/25114770

(Note that despite the question specifying language agnostic answers, the
second most highly-rated answer is language specific.)


The Wikipedia article is heavy going, but worth reading:

https://en.wikipedia.org/wiki/Type_theory


As Python programmers, the simplest way to look at this question is:

(1) Class (also known as a "type", although for the avoidance of confusion I
shall avoid that terminology here) in the Python sense is an entity which
tells the interpreter what methods and attributes a value has. In other
words, classes define behaviour.

In Python classes are "first-class values" and can be created on the fly,
bound to names, put inside lists, etc. This is not essential to the concept
though, many languages, such as Java, do not treat classes as first-class.

Unfortunately, for historical reasons, the function[1] which returns the
class of a value is called "type()". And the class of all classes (the
metaclass) is also called "type". Which made type and class synonyms from
Python 2.2 onwards.


(2) Type, in the PEP 483/484 sense, is a label which tells the static
type-checker what kind of values are acceptable in a particular place. This
is the "type theory" sense as in the Wikipedia article.

In principle these PEP 484 types could be completely abstract, but Python's
typing module will generally use classes (sense 1 above) to implement these
label.


(3) In Python especially, the differences between (1) and (2) are more
theoretical than practical, but there are a couple of obvious exceptions:

- Union types should be considered a purely abstract label. (In practice,
they'll actually be implemented as a class, but that's just an
implementation detail.) Unions cannot be instantiated, nor subclassed. For
example, take this example:


py> import typing
py> Foo = typing.Union[str, int]

Foo is now a label to tell the type-checker you will accept "a str, or an
int, but nothing else". It is *not* a subclass of str and int. There is no
such thing as an instance of Foo, nor can you subclass it. If you try, you
get a TypeError:

py> Foo() 
[...]
TypeError: Cannot instantiate 

class Bar(Foo): pass
[...]
TypeError: Cannot subclass typing.Union[str, int]

This is from Python 3.6 pre-alpha. The messages may change in the future.

Foo is only used as a purely abstract label to tell the type-checker to
accept either a str, or an int. So in that sense, although the Python
implementation of Foo is a class object, that's just a detail of the
implementation.


- The other obvious example is Any. Like Unions, Any cannot be instantiated
or subclassed and is intended as a purely abstract label for "anything at
all". One can consider Any to be the equivalent of a Union of "all possible
types", and it basically exists for the type-checker to record a state of
maximum ignorance. ("I don't know what this will be, it could be
anything.")


So types and classes essentially have different purposes, even though they
overlap. Types (in this "type theory", PEP 484 sense) are for proving
compile-time facts about code. Classes (in Python) are for specifying the
behaviour and implementation of objects.





[1] Actually, the function "type()" and the class "type" are implemented as
the same object, which does two different things depending on how many
arguments it gets. With one argument, type(x) returns the class of x. With
three arguments, type(name, bases, namespace) creates and returns a new
class.


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling python from C with OpenMP

2016-05-13 Thread Paul Rubin
Dennis Lee Bieber  writes:
>   It's been tried -- but the non-GIL implementations tend to be
> slower at everything else.

Has Micropython been compared?  CPython needs the GIL because of its
frequent twiddling of reference counts.  Without the GIL, multi-threaded
CPython would have to acquire and release a lock whenever it touched a
refcount, which slows things down badly.

MicroPython uses a tracing garbage collector instead of refcounts, so
there's no issue of having to lock refcounts all the time.  It's fairly
common in such systems to stop all the user threads during GC, but they
can happily run in parallel the rest of the time.  

Come to think of it, I don't know if MicroPython currently supports
threads at all!  But its implementation style (i.e. no refcounts) is
more parallelism-friendly than CPython's.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Distinction between “class” and “type”

2016-05-13 Thread Paul Rubin
Terry Reedy  writes:
> I suspect that one could produce a class that is not a type, in
> Guido's meaning, with a metaclass that is not a subclass of the type
> class.  I don't otherwise know what Guido might have meant.

I think meant that if X is a class, then X is (usually) also a type; but
the reverse is not true.  We used to think of type and class as the same
thing in practice.  We didn't have to concern ourselves about too much
about theoretical or pedantic differences that might exist.

Now with PEP 484, the situation where X is a type but not a class is
significant enough in practice that we have to be more careful about the
distinction than we were in the Python 2 era.

There may(?) also be situations where X is a class but not a type, but I
don't think that's being considered as important as the other direction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Distinction between “class” and “type”

2016-05-13 Thread Terry Reedy

On 5/13/2016 1:07 AM, Ben Finney wrote:

Howdy all,

Ever since Python's much-celebrated Grand Unification of classes and
types, I have used those terms interchangeably: every class is a type,
and every type is a class.

That may be an unwise conflation. With the recent rise of optional type
annotation in Python 3, more people are speaking about the important
distinction between a class and a type.

This recent message from GvR, discussing a relevant PEP, advocates
keeping them separate:

PEP 484 […] tries to make a clear terminological between classes
(the things you have at runtime) and types (the things that type
checkers care about).

There's a big overlap because most classes are also types -- but not
the other way around! E.g. Any is a type but not a class (you can
neither inherit from Any nor instantiate it), and the same is true
for unions and type variables. […]

https://mail.python.org/pipermail/python-ideas/2016-May/040237.html>

As a Bear of Little Brain, this leaves me clueless. What is the
distinction Guido alludes to, and how are Python classes not also types?


I suspect that one could produce a class that is not a type, in Guido's 
meaning, with a metaclass that is not a subclass of the type class.  I 
don't otherwise know what Guido might have meant.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
What have code you tried? What error message are you receiving?

On Fri, May 13, 2016, 5:54 PM David Shi  wrote:

> Hello, Michael,
>
> How to convert a float type column into an integer or label or string type?
>
>
> On Friday, 13 May 2016, 22:02, Michael Selik 
> wrote:
>
>
> To clarify that you're specifying the index as a label, use df.iloc
>
> >>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))
> >>> df
>X
> a  0
> b  1
> c  2
> d  3
> >>> df.loc['a']
> X0
> Name: a, dtype: int64
> >>> df.iloc[0]
> X0
> Name: a, dtype: int64
>
> On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:
>
> Dear Michael,
>
> To avoid complication, I only groupby using one column.
>
> It is OK now.  But, how to refer to new row index?  How do I use floating
> index?
>
> Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0,
>   17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 
> 27.0,
>   28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 
> 38.0,
>   39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 
> 50.0,
>   51.0, 53.0, 54.0, 55.0, 56.0],
>  dtype='float64', name=u'StateFIPS')
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:43, Michael Selik 
> wrote:
>
>
> Here's an example.
>
> >>> import pandas as pd
> >>> df = pd.DataFrame({'group': list('AB') * 2, 'data': range(4)},
> index=list('wxyz'))
> >>> df
>data group
> w 0 A
> x 1 B
> y 2 A
> z 3 B
> >>> df = df.reset_index()
> >>> df
>   index  data group
> 0 w 0 A
> 1 x 1 B
> 2 y 2 A
> 3 z 3 B
> >>> df.groupby('group').max()
>   index  data
> group
> A y 2
> B z 3
>
> If that doesn't help, you'll need to explain what you're trying to
> accomplish in detail -- what variables you started with, what
> transformations you want to do, and what variables you hope to have when
> finished.
>
> On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:
>
> Hello, Michael,
>
> I changed groupby with one column.
>
> The index is different.
>
> Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
>   u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
>   u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
>   u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
>   u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
>   u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
>   u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
>   u'WY'],
>   dtype='object', name=0)
>
>
> How to use this index?
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:19, David Shi  wrote:
>
>
> Hello, Michael,
>
> I typed in df.index
>
> I got the following
>
> MultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 
> 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 
> 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 54.0, 55.0, 
> 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', u'FL', u'GA', 
> u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', u'ME', u'MI', 
> u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', u'NM', u'NV', 
> u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', u'TN', 
> u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
>labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
> 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
> 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 
> 8, 9, 11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 
> 29, 30, 32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 
> 47, 49]],
>names=[u'StateFIPS', 0])
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:11, David Shi  wrote:
>
>
> Dear Michael,
>
> I have done a number of operation in between.
>
> Providing that information does not help you
>
> How to reset index after grouping and various operations is of interest.
>
> How to type in a command to find out its current dataframe?
>
> Regards.
>
> David
>
>
> On Friday, 13 May 2016, 20:58, Michael Selik 
> wrote:
>
>
> Just in case I misunderstood, why don't you make a little example of
> before and after the grouping? This mailing list does not accept
> attachments, so you'll have to make do with pasting a few rows of
> comma-separated or tab-separated values.
>
> On Fri, May 13, 2016 at 3:56 PM Michael Selik 
> wrote:
>
> In order to preserve your index after the a

Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
How to convert a float type column into an integer or label or string type? 

On Friday, 13 May 2016, 22:02, Michael Selik  
wrote:
 

 To clarify that you're specifying the index as a label, use df.iloc
    >>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))    >>> df       
X    a  0    b  1    c  2    d  3    >>> df.loc['a']    X    0    Name: a, 
dtype: int64    >>> df.iloc[0]    X    0    Name: a, dtype: int64
On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:

Dear Michael,
To avoid complication, I only groupby using one column.
It is OK now.  But, how to refer to new row index?  How do I use floating index?
Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 16.0,
  17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0,
  28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0,
  39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0,
  51.0, 53.0, 54.0, 55.0, 56.0],
 dtype='float64', name=u'StateFIPS')
Regards.
David 

On Friday, 13 May 2016, 21:43, Michael Selik  
wrote:
 

 Here's an example.
    >>> import pandas as pd    >>> df = pd.DataFrame({'group': list('AB') * 2, 
'data': range(4)}, index=list('wxyz'))    >>> df       data group    w     0    
 A    x     1     B    y     2     A    z     3     B    >>> df = 
df.reset_index()    >>> df      index  data group    0     w     0     A    1   
  x     1     B    2     y     2     A    3     z     3     B    >>> 
df.groupby('group').max()          index  data    group    A         y     2    
B         z     3
If that doesn't help, you'll need to explain what you're trying to accomplish 
in detail -- what variables you started with, what transformations you want to 
do, and what variables you hope to have when finished.
On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:

Hello, Michael,
I changed groupby with one column.
The index is different.
Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
  u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
  u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
  u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
  u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
  u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
  u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
  u'WY'],
  dtype='object', name=0)
How to use this index?
Regards.
David 

On Friday, 13 May 2016, 21:19, David Shi  wrote:
 

 Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 47, 49]],
   names=[u'StateFIPS', 0])Regards.
David 

On Friday, 13 May 2016, 21:11, David Shi  wrote:
 

 Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset index after grouping and various operations is of interest.
How to type in a command to find out its current dataframe?
Regards.
David 

On Friday, 13 May 2016, 20:58, Michael Selik  
wrote:
 

 Just in case I misunderstood, why don't you make a little example of before 
and after the grouping? This mailing list does not accept attachments, so 
you'll have to make do with pasting a few rows of comma-separated or 
tab-separated values.
On Fri, May 13, 2016 at 3:56 PM Michael Selik  wrote:

In order to preserve your index after the aggregation, you need to make sure it 
is considered a data column (via reset_index) and then choose how your 
aggregation will operate on that column.
On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

Hello, Michael,
Why reset_index before grouping?
Regards.
David 

  On Friday, 13 May 2016, 17:57, Michael Selik  wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.

How to use pip to install dtrx?

2016-05-13 Thread Ehsan Hajiramezanali
Hi,

I want to use pip to install dtrx. However, I got the following error.

~~~
$ pip install --allow-external dtrx dtrx
DEPRECATION: --allow-external has been deprecated and will be removed
in the future. Due to changes in the repository protocol, it no longer
has any effect.
Collecting dtrx
  Could not find a version that satisfies the requirement dtrx (from versions: )
No matching distribution found for dtrx
~~~

Is there any way to solve this problem?

Thanks in advance.

Best regards,
Ehsan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
To clarify that you're specifying the index as a label, use df.iloc

>>> df = pd.DataFrame({'X': range(4)}, index=list('abcd'))
>>> df
   X
a  0
b  1
c  2
d  3
>>> df.loc['a']
X0
Name: a, dtype: int64
>>> df.iloc[0]
X0
Name: a, dtype: int64

On Fri, May 13, 2016 at 4:54 PM David Shi  wrote:

> Dear Michael,
>
> To avoid complication, I only groupby using one column.
>
> It is OK now.  But, how to refer to new row index?  How do I use floating
> index?
>
> Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0,
>   17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 
> 27.0,
>   28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 
> 38.0,
>   39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 
> 50.0,
>   51.0, 53.0, 54.0, 55.0, 56.0],
>  dtype='float64', name=u'StateFIPS')
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:43, Michael Selik 
> wrote:
>
>
> Here's an example.
>
> >>> import pandas as pd
> >>> df = pd.DataFrame({'group': list('AB') * 2, 'data': range(4)},
> index=list('wxyz'))
> >>> df
>data group
> w 0 A
> x 1 B
> y 2 A
> z 3 B
> >>> df = df.reset_index()
> >>> df
>   index  data group
> 0 w 0 A
> 1 x 1 B
> 2 y 2 A
> 3 z 3 B
> >>> df.groupby('group').max()
>   index  data
> group
> A y 2
> B z 3
>
> If that doesn't help, you'll need to explain what you're trying to
> accomplish in detail -- what variables you started with, what
> transformations you want to do, and what variables you hope to have when
> finished.
>
> On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:
>
> Hello, Michael,
>
> I changed groupby with one column.
>
> The index is different.
>
> Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
>   u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
>   u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
>   u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
>   u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
>   u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
>   u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
>   u'WY'],
>   dtype='object', name=0)
>
>
> How to use this index?
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:19, David Shi  wrote:
>
>
> Hello, Michael,
>
> I typed in df.index
>
> I got the following
>
> MultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 
> 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 
> 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 54.0, 55.0, 
> 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', u'FL', u'GA', 
> u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', u'ME', u'MI', 
> u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', u'NM', u'NV', 
> u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', u'TN', 
> u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
>labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
> 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
> 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 
> 8, 9, 11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 
> 29, 30, 32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 
> 47, 49]],
>names=[u'StateFIPS', 0])
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:11, David Shi  wrote:
>
>
> Dear Michael,
>
> I have done a number of operation in between.
>
> Providing that information does not help you
>
> How to reset index after grouping and various operations is of interest.
>
> How to type in a command to find out its current dataframe?
>
> Regards.
>
> David
>
>
> On Friday, 13 May 2016, 20:58, Michael Selik 
> wrote:
>
>
> Just in case I misunderstood, why don't you make a little example of
> before and after the grouping? This mailing list does not accept
> attachments, so you'll have to make do with pasting a few rows of
> comma-separated or tab-separated values.
>
> On Fri, May 13, 2016 at 3:56 PM Michael Selik 
> wrote:
>
> In order to preserve your index after the aggregation, you need to make
> sure it is considered a data column (via reset_index) and then choose how
> your aggregation will operate on that column.
>
> On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:
>
> Hello, Michael,
>
> Why reset_index before grouping?
>
> Regards.
>
> David
>
>
> On Friday, 13 May

Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Dear Michael,
To avoid complication, I only groupby using one column.
It is OK now.  But, how to refer to new row index?  How do I use floating index?
Float64Index([ 1.0,  4.0,  5.0,  6.0,  8.0,  9.0, 10.0, 11.0, 12.0, 13.0, 16.0,
  17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0,
  28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0,
  39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0,
  51.0, 53.0, 54.0, 55.0, 56.0],
 dtype='float64', name=u'StateFIPS')
Regards.
David 

On Friday, 13 May 2016, 21:43, Michael Selik  
wrote:
 

 Here's an example.
    >>> import pandas as pd    >>> df = pd.DataFrame({'group': list('AB') * 2, 
'data': range(4)}, index=list('wxyz'))    >>> df       data group    w     0    
 A    x     1     B    y     2     A    z     3     B    >>> df = 
df.reset_index()    >>> df      index  data group    0     w     0     A    1   
  x     1     B    2     y     2     A    3     z     3     B    >>> 
df.groupby('group').max()          index  data    group    A         y     2    
B         z     3
If that doesn't help, you'll need to explain what you're trying to accomplish 
in detail -- what variables you started with, what transformations you want to 
do, and what variables you hope to have when finished.
On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:

Hello, Michael,
I changed groupby with one column.
The index is different.
Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
  u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
  u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
  u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
  u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
  u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
  u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
  u'WY'],
  dtype='object', name=0)
How to use this index?
Regards.
David 

On Friday, 13 May 2016, 21:19, David Shi  wrote:
 

 Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 47, 49]],
   names=[u'StateFIPS', 0])Regards.
David 

On Friday, 13 May 2016, 21:11, David Shi  wrote:
 

 Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset index after grouping and various operations is of interest.
How to type in a command to find out its current dataframe?
Regards.
David 

On Friday, 13 May 2016, 20:58, Michael Selik  
wrote:
 

 Just in case I misunderstood, why don't you make a little example of before 
and after the grouping? This mailing list does not accept attachments, so 
you'll have to make do with pasting a few rows of comma-separated or 
tab-separated values.
On Fri, May 13, 2016 at 3:56 PM Michael Selik  wrote:

In order to preserve your index after the aggregation, you need to make sure it 
is considered a data column (via reset_index) and then choose how your 
aggregation will operate on that column.
On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

Hello, Michael,
Why reset_index before grouping?
Regards.
David 

  On Friday, 13 May 2016, 17:57, Michael Selik  wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

 



   

   

   


  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
Here's an example.

>>> import pandas as pd
>>> df = pd.DataFrame({'group': list('AB') * 2, 'data': range(4)},
index=list('wxyz'))
>>> df
   data group
w 0 A
x 1 B
y 2 A
z 3 B
>>> df = df.reset_index()
>>> df
  index  data group
0 w 0 A
1 x 1 B
2 y 2 A
3 z 3 B
>>> df.groupby('group').max()
  index  data
group
A y 2
B z 3

If that doesn't help, you'll need to explain what you're trying to
accomplish in detail -- what variables you started with, what
transformations you want to do, and what variables you hope to have when
finished.

On Fri, May 13, 2016 at 4:36 PM David Shi  wrote:

> Hello, Michael,
>
> I changed groupby with one column.
>
> The index is different.
>
> Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
>   u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
>   u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
>   u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
>   u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
>   u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
>   u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
>   u'WY'],
>   dtype='object', name=0)
>
>
> How to use this index?
>
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:19, David Shi  wrote:
>
>
> Hello, Michael,
>
> I typed in df.index
>
> I got the following
>
> MultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 
> 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 
> 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 
> 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 54.0, 55.0, 
> 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', u'FL', u'GA', 
> u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', u'ME', u'MI', 
> u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', u'NM', u'NV', 
> u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', u'TN', 
> u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
>labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
> 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 
> 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 
> 8, 9, 11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 
> 29, 30, 32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 
> 47, 49]],
>names=[u'StateFIPS', 0])
>
> Regards.
>
>
> David
>
>
>
> On Friday, 13 May 2016, 21:11, David Shi  wrote:
>
>
> Dear Michael,
>
> I have done a number of operation in between.
>
> Providing that information does not help you
>
> How to reset index after grouping and various operations is of interest.
>
> How to type in a command to find out its current dataframe?
>
> Regards.
>
> David
>
>
> On Friday, 13 May 2016, 20:58, Michael Selik 
> wrote:
>
>
> Just in case I misunderstood, why don't you make a little example of
> before and after the grouping? This mailing list does not accept
> attachments, so you'll have to make do with pasting a few rows of
> comma-separated or tab-separated values.
>
> On Fri, May 13, 2016 at 3:56 PM Michael Selik 
> wrote:
>
> In order to preserve your index after the aggregation, you need to make
> sure it is considered a data column (via reset_index) and then choose how
> your aggregation will operate on that column.
>
> On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:
>
> Hello, Michael,
>
> Why reset_index before grouping?
>
> Regards.
>
> David
>
>
> On Friday, 13 May 2016, 17:57, Michael Selik 
> wrote:
>
>
>
>
> On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list <
> python-list@python.org> wrote:
>
> I lost my indexes after grouping in Pandas.
> I managed to rest_index and got back the index column.
> But How can I get back a index row?
>
>
> Was the grouping an aggregation? If so, the original indexes are
> meaningless. What you could do is reset_index before the grouping and when
> you aggregate decide how to handle the formerly-known-as-index column (min,
> max, mean, ?).
>
>
>
>
>
>
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
I changed groupby with one column.
The index is different.
Index([   u'AL',u'AR',u'AZ',u'CA',u'CO',u'CT',u'DC',
  u'DE',u'FL',u'GA',u'IA',u'ID',u'IL',u'IN',
  u'KS',u'KY',u'LA',u'MA',u'MD',u'ME',u'MI',
  u'MN',u'MO',u'MS',u'MT',u'NC',u'ND',u'NE',
  u'NH',u'NJ',u'NM',u'NV',u'NY',u'OH',u'OK',
  u'OR',u'PA',u'RI',u'SC',u'SD', u'State',u'TN',
  u'TX',u'UT',u'VA',u'VT',u'WA',u'WI',u'WV',
  u'WY'],
  dtype='object', name=0)
How to use this index?
Regards.
David 

On Friday, 13 May 2016, 21:19, David Shi  wrote:
 

 Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 47, 49]],
   names=[u'StateFIPS', 0])Regards.
David 

On Friday, 13 May 2016, 21:11, David Shi  wrote:
 

 Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset index after grouping and various operations is of interest.
How to type in a command to find out its current dataframe?
Regards.
David 

On Friday, 13 May 2016, 20:58, Michael Selik  
wrote:
 

 Just in case I misunderstood, why don't you make a little example of before 
and after the grouping? This mailing list does not accept attachments, so 
you'll have to make do with pasting a few rows of comma-separated or 
tab-separated values.
On Fri, May 13, 2016 at 3:56 PM Michael Selik  wrote:

In order to preserve your index after the aggregation, you need to make sure it 
is considered a data column (via reset_index) and then choose how your 
aggregation will operate on that column.
On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

Hello, Michael,
Why reset_index before grouping?
Regards.
David 

  On Friday, 13 May 2016, 17:57, Michael Selik  wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

 



   

   

   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Design: Idiom for classes and methods that are customizable by the user?

2016-05-13 Thread Michael Selik
On Fri, May 13, 2016 at 2:41 AM Gregory Ewing 
wrote:

> Dirk Bächle wrote:
> > I'm currently following the "Factory" pattern (more or less) as I know
> > it from C++ and similar languages.
>
> This statement sets off alarm bells for me. If you're using some
> design pattern in Python just because you learned to do it that
> way in C++/Java/whatever, you're probably making it more
> complicated than it needs to be.
>

I share Greg's trepidation when I hear a phrase like that, but the general
idea of a registry of classes or functions and then picking the right one
based on string input is fine.

How would the API work for custom Taskmasters? It's not so great to require
that the user must explicitly ``add`` their derived class after defining
it. Perhaps that add function could be a decorator?

def register(key):
def decorator(cls):
if not issubclass(cls, Taskmaster):
raise TypeError('You fool!')
registry[key] = cls
return decorator

@register('noclean')
class NoCleanTaskMaster(TaskMaster):
"Looks clean enough, why worry?"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
I typed in df.index
I got the followingMultiIndex(levels=[[1.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 
11.0, 12.0, 13.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 
26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 
39.0, 40.0, 41.0, 42.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0, 51.0, 53.0, 
54.0, 55.0, 56.0], [u'AL', u'AR', u'AZ', u'CA', u'CO', u'CT', u'DC', u'DE', 
u'FL', u'GA', u'IA', u'ID', u'IL', u'IN', u'KS', u'KY', u'LA', u'MA', u'MD', 
u'ME', u'MI', u'MN', u'MO', u'MS', u'MT', u'NC', u'ND', u'NE', u'NH', u'NJ', 
u'NM', u'NV', u'NY', u'OH', u'OK', u'OR', u'PA', u'RI', u'SC', u'SD', u'State', 
u'TN', u'TX', u'UT', u'VA', u'VT', u'WA', u'WI', u'WV', u'WY']],
   labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48], [0, 2, 1, 3, 4, 5, 7, 6, 8, 9, 
11, 12, 13, 10, 14, 15, 16, 19, 18, 17, 20, 21, 23, 22, 24, 27, 31, 28, 29, 30, 
32, 25, 26, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 45, 44, 46, 48, 47, 49]],
   names=[u'StateFIPS', 0])Regards.
David 

On Friday, 13 May 2016, 21:11, David Shi  wrote:
 

 Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset index after grouping and various operations is of interest.
How to type in a command to find out its current dataframe?
Regards.
David 

On Friday, 13 May 2016, 20:58, Michael Selik  
wrote:
 

 Just in case I misunderstood, why don't you make a little example of before 
and after the grouping? This mailing list does not accept attachments, so 
you'll have to make do with pasting a few rows of comma-separated or 
tab-separated values.
On Fri, May 13, 2016 at 3:56 PM Michael Selik  wrote:

In order to preserve your index after the aggregation, you need to make sure it 
is considered a data column (via reset_index) and then choose how your 
aggregation will operate on that column.
On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

Hello, Michael,
Why reset_index before grouping?
Regards.
David 

  On Friday, 13 May 2016, 17:57, Michael Selik  wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

 



   

   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling python from C with OpenMP

2016-05-13 Thread Øystein Schønning-Johansen
On Friday, May 13, 2016 at 7:12:33 PM UTC+2, MRAB wrote:
> Every PyGILState_Ensure call must be matched with a PyGILState_Release 
> call. The way it's currently written, it won't call PyGILState_Release 
> if ret is NULL.

Yeah, that's tiny bug, however it is not the main problem...
 
> However, I don't think you'll gain much here because you can gain from 
> multi-threading only if the threads can run in parallel. You need to 
> hold the GIL while making Python calls, and only 1 thread can hold the 
> GIL at any time.

In addition to the fact that it still does not work, what you here point out, 
is the main problem. I actually think I'm giving up for now. Maybe I'm able to 
solve this later (when python does not use a GIL anymore...?)

Thanks to Sturla and MRAB anyway!
-Øystein

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Dear Michael,
I have done a number of operation in between.
Providing that information does not help you
How to reset index after grouping and various operations is of interest.
How to type in a command to find out its current dataframe?
Regards.
David 

On Friday, 13 May 2016, 20:58, Michael Selik  
wrote:
 

 Just in case I misunderstood, why don't you make a little example of before 
and after the grouping? This mailing list does not accept attachments, so 
you'll have to make do with pasting a few rows of comma-separated or 
tab-separated values.
On Fri, May 13, 2016 at 3:56 PM Michael Selik  wrote:

In order to preserve your index after the aggregation, you need to make sure it 
is considered a data column (via reset_index) and then choose how your 
aggregation will operate on that column.
On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

Hello, Michael,
Why reset_index before grouping?
Regards.
David 

  On Friday, 13 May 2016, 17:57, Michael Selik  wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

 



   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Dear MIchael,
I am very confused.
Can you send me a link to a working example?
Regards.
David 

On Friday, 13 May 2016, 20:56, Michael Selik  
wrote:
 

 In order to preserve your index after the aggregation, you need to make sure 
it is considered a data column (via reset_index) and then choose how your 
aggregation will operate on that column.
On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

Hello, Michael,
Why reset_index before grouping?
Regards.
David 

  On Friday, 13 May 2016, 17:57, Michael Selik  wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

 


   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
Just in case I misunderstood, why don't you make a little example of before
and after the grouping? This mailing list does not accept attachments, so
you'll have to make do with pasting a few rows of comma-separated or
tab-separated values.

On Fri, May 13, 2016 at 3:56 PM Michael Selik 
wrote:

> In order to preserve your index after the aggregation, you need to make
> sure it is considered a data column (via reset_index) and then choose how
> your aggregation will operate on that column.
>
> On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:
>
>> Hello, Michael,
>>
>> Why reset_index before grouping?
>>
>> Regards.
>>
>> David
>>
>>
>> On Friday, 13 May 2016, 17:57, Michael Selik 
>> wrote:
>>
>>
>>
>>
>> On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list <
>> python-list@python.org> wrote:
>>
>> I lost my indexes after grouping in Pandas.
>> I managed to rest_index and got back the index column.
>> But How can I get back a index row?
>>
>>
>> Was the grouping an aggregation? If so, the original indexes are
>> meaningless. What you could do is reset_index before the grouping and when
>> you aggregate decide how to handle the formerly-known-as-index column (min,
>> max, mean, ?).
>>
>>
>>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
In order to preserve your index after the aggregation, you need to make
sure it is considered a data column (via reset_index) and then choose how
your aggregation will operate on that column.

On Fri, May 13, 2016 at 3:29 PM David Shi  wrote:

> Hello, Michael,
>
> Why reset_index before grouping?
>
> Regards.
>
> David
>
>
> On Friday, 13 May 2016, 17:57, Michael Selik 
> wrote:
>
>
>
>
> On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list <
> python-list@python.org> wrote:
>
> I lost my indexes after grouping in Pandas.
> I managed to rest_index and got back the index column.
> But How can I get back a index row?
>
>
> Was the grouping an aggregation? If so, the original indexes are
> meaningless. What you could do is reset_index before the grouping and when
> you aggregate decide how to handle the formerly-known-as-index column (min,
> max, mean, ?).
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,
Why reset_index before grouping?
Regards.
David 

On Friday, 13 May 2016, 17:57, Michael Selik  
wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

   
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread David Shi via Python-list
Hello, Michael,Thank you.  Yes, aster grouping I lost my indexing in both x, y 
directions.
How to convert a row, and a column into indexes or labels? 

On Friday, 13 May 2016, 17:57, Michael Selik  
wrote:
 

 

On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list 
 wrote:

I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?


Was the grouping an aggregation? If so, the original indexes are meaningless. 
What you could do is reset_index before the grouping and when you aggregate 
decide how to handle the formerly-known-as-index column (min, max, mean, ?).

  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An educational site written in Python (from YCombinator's RFS)

2016-05-13 Thread Ned Batchelder
On Friday, May 13, 2016 at 2:16:37 PM UTC-4, Cai Gengyang wrote:
> Ned, 
> 
> At the risk of sounding like a naggy grandmother, I am not trying to argue 
> with you (since it is pointless arguing over the internet with a stranger 
> whom i don't know and I hate arguing) but It is important to note that 
> whether there is a need/demand for a competitor or clone is not up to you or 
> me to decide, it is up to the market and users to decide. If following your 
> logic that there is no need for competition, then we would only have 1 search 
> engine in the world. It is competition that creates real wealth in the world 
> and improvement in people's lives. Before Google, there were already tons of 
> search engines in existence like Yahoo and Altavista that had hundreds of 
> millions if not billions of users. I am not sure exactly what special "sauce" 
> that Google had that made it scale so fast so successfully and become the 
> dominant search engine over others , but the point I was simply trying to 
> make is that competition is a great thing in the free market, and that users 
> are always wil
 ling to switch or use a new alternative if it is significantly better / 
different or novel (different design). Very few things are totally novel ... 
most technologies are copycats of one another. Even Steve Jobs, whom many would 
describe as the most creative tech innovator for the past 20 or 30 years 
probably stole / copied / cloned his ideas for his many inventions from various 
other sources (while constantly whining and accusing Microsoft and Bill Gates 
of ripping off his ideas lol). Amongst the "educational startup" sector, there 
are also several up and coming sites : 
http://www.inc.com/ilan-mochari/16-startups-that-will-disrupt-the-education-market.html
 and I predict that there will be demand for more similar sites in the future 
by users 

Sorry I wasn't clear.  I certainly didn't mean to squelch competition,
and I'm not looking to argue.  I just wanted to make sure you understood
the Open edX option.

I wish you all the best.  More and better educational sites will be good
for the world.

--Ned.

> 
> 
> As Paul Graham mentioned : "Startups are often ruthless competitors, but 
> they're competing in a game won by making what people want."
> 
> 
> On Saturday, May 14, 2016 at 12:52:58 AM UTC+8, Ned Batchelder wrote:
> > On Friday, May 13, 2016 at 12:05:33 PM UTC-4, Cai Gengyang wrote:
> > > edx.org is a great example , perhaps a competitor / clone with different 
> > > functionalities and better design , more videos, graphics , more 
> > > interactive 
> > 
> > As I mentioned in a previous reply, edx.org runs on Open edX, which is
> > open source, written in Python.  There's no need for a competitor/clone,
> > you can use it as a starting point, and improve it how you like.
> > 
> > The content is completely up to the course designer, you can include
> > whatever videos or graphics you like.  For interactives, we have have
> > the XBlock API which lets you create new courseware components that
> > work however you like.
> > 
> > --Ned.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Distinction between “class” and “type”

2016-05-13 Thread Michael Selik
On Fri, May 13, 2016 at 1:10 AM Ben Finney 
wrote:

> Howdy all,
>
> Ever since Python's much-celebrated Grand Unification of classes and
> types, I have used those terms interchangeably: every class is a type,
> and every type is a class.
>
> That may be an unwise conflation. With the recent rise of optional type
> annotation in Python 3, more people are speaking about the important
> distinction between a class and a type.
>

The concept of a type existed before the concept of object-oriented
programming. A type is more of a mathematical concept. Do some reading on
"type theory" if you'd like to know more. A type system ideally allows
logical deductions about the validity of your expressions/statements. Stuff
a static analyzer is good at.

With the advent of object-orientation and the concept of inheritance,
things have gotten a little confused. You could make a distinction between
"type inheritance" and "implementation/code inheritance" but many languages
do not. When you make a subclass in Python, it inherits both the type and
the code of the superclass. I suppose you could say the composition vs
inheritance argument stems from some people advocating code inheritance
without type inheritance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An educational site written in Python (from YCombinator's RFS)

2016-05-13 Thread Cai Gengyang
Ned, 

At the risk of sounding like a naggy grandmother, I am not trying to argue with 
you (since it is pointless arguing over the internet with a stranger whom i 
don't know and I hate arguing) but It is important to note that whether there 
is a need/demand for a competitor or clone is not up to you or me to decide, it 
is up to the market and users to decide. If following your logic that there is 
no need for competition, then we would only have 1 search engine in the world. 
It is competition that creates real wealth in the world and improvement in 
people's lives. Before Google, there were already tons of search engines in 
existence like Yahoo and Altavista that had hundreds of millions if not 
billions of users. I am not sure exactly what special "sauce" that Google had 
that made it scale so fast so successfully and become the dominant search 
engine over others , but the point I was simply trying to make is that 
competition is a great thing in the free market, and that users are always willi
 ng to switch or use a new alternative if it is significantly better / 
different or novel (different design). Very few things are totally novel ... 
most technologies are copycats of one another. Even Steve Jobs, whom many would 
describe as the most creative tech innovator for the past 20 or 30 years 
probably stole / copied / cloned his ideas for his many inventions from various 
other sources (while constantly whining and accusing Microsoft and Bill Gates 
of ripping off his ideas lol). Amongst the "educational startup" sector, there 
are also several up and coming sites : 
http://www.inc.com/ilan-mochari/16-startups-that-will-disrupt-the-education-market.html
 and I predict that there will be demand for more similar sites in the future 
by users 


As Paul Graham mentioned : "Startups are often ruthless competitors, but 
they're competing in a game won by making what people want."


On Saturday, May 14, 2016 at 12:52:58 AM UTC+8, Ned Batchelder wrote:
> On Friday, May 13, 2016 at 12:05:33 PM UTC-4, Cai Gengyang wrote:
> > edx.org is a great example , perhaps a competitor / clone with different 
> > functionalities and better design , more videos, graphics , more 
> > interactive 
> 
> As I mentioned in a previous reply, edx.org runs on Open edX, which is
> open source, written in Python.  There's no need for a competitor/clone,
> you can use it as a starting point, and improve it how you like.
> 
> The content is completely up to the course designer, you can include
> whatever videos or graphics you like.  For interactives, we have have
> the XBlock API which lets you create new courseware components that
> work however you like.
> 
> --Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling python from C with OpenMP

2016-05-13 Thread MRAB

On 2016-05-13 17:22, Øystein Schønning-Johansen wrote:

On Friday, May 13, 2016 at 2:04:53 AM UTC+2, Sturla Molden wrote:

You must own the GIL before you can safely use the Python C API, object
creation and refcounting in particular. Use the "Simplified GIL API" to
grab the GIL and release it when you are done.


I've now read about the GIL and it looks like I am in deep problems.

I've added the GILState lock to the threaded loop like this:

#pragma omp parallel for
for( int i = 0; i < 10; i++ ){
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyObject *ret = PyObject_CallMethod( mult_obj, "do_multiply", "i", i );
if( !ret ){
printf("Cannot call 'do_multiply'\n");
continue;
}
printf("The value calculated in Python was: %3d\n", (int) 
PyLong_AsLong(ret));
Py_DECREF(ret);
PyGILState_Release(gstate);
}

 but still no success. Have I done it right?

regs,
-Øystein

Every PyGILState_Ensure call must be matched with a PyGILState_Release 
call. The way it's currently written, it won't call PyGILState_Release 
if ret is NULL.


However, I don't think you'll gain much here because you can gain from 
multi-threading only if the threads can run in parallel. You need to 
hold the GIL while making Python calls, and only 1 thread can hold the 
GIL at any time.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.5.1 Not Working

2016-05-13 Thread Random832
On Fri, May 13, 2016, at 12:18, Aidan Silcock via Python-list wrote:
> 
> 
> Sent from Yahoo Mail on Android 
>  
>   On Fri, 13 May, 2016 at 16:59, Aidan Silcock
>   wrote:   HelloI have tried to download python 3.5.1 today and it has
>   downloaded but each time I try to open it it says I need to Modify,
>   Repair or Uninstall the program.I have tried repairing it neumerous
>   times and it will say it was successful but then when I go to open it
>   again it comes up with the same message.Can you help?

The file you downloaded is the installer, which installs (or modifies,
repairs, or uninstalls) Python. To actually *run* Python you need to
find it in the start menu. Don't keep reopening the downloaded file.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to put back a number-based index

2016-05-13 Thread Michael Selik
On Fri, May 13, 2016 at 12:27 PM David Shi via Python-list <
python-list@python.org> wrote:

> I lost my indexes after grouping in Pandas.
> I managed to rest_index and got back the index column.
> But How can I get back a index row?
>

Was the grouping an aggregation? If so, the original indexes are
meaningless. What you could do is reset_index before the grouping and when
you aggregate decide how to handle the formerly-known-as-index column (min,
max, mean, ?).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An educational site written in Python (from YCombinator's RFS)

2016-05-13 Thread Ned Batchelder
On Friday, May 13, 2016 at 12:05:33 PM UTC-4, Cai Gengyang wrote:
> edx.org is a great example , perhaps a competitor / clone with different 
> functionalities and better design , more videos, graphics , more interactive 

As I mentioned in a previous reply, edx.org runs on Open edX, which is
open source, written in Python.  There's no need for a competitor/clone,
you can use it as a starting point, and improve it how you like.

The content is completely up to the course designer, you can include
whatever videos or graphics you like.  For interactives, we have have
the XBlock API which lets you create new courseware components that
work however you like.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Skipping test using unittest SkipTest and exit status

2016-05-13 Thread Steven D'Aprano
On Sat, 14 May 2016 02:23 am, Ganesh Pal wrote:

> Hi Team,
> 
> Iam on  python 2.7 and Linux . I need inputs on the below  program  ,

"I am" is two words, not one. I hope you wouldn't write "Youare"
or "Heis" :-) Whenever you write "Iam", I read it as the name "Ian", which
is very distracting.


> Iam skipping the unittest  from setUpClass in following way  # raise
> unittest.SkipTest(message)
> 
> The test are getting skipped but   I have two problem .
> 
> (1) This script  is in turn read by other  scripts  which considers the
> test have passed based on the scripts return code , but the test have
> actually been skipped   ,  How do include an exit status to indicates that
> the test have failed

But the test *hasn't* failed. A skipped test is not a failed test.

If you want the test to count as failed, you must let it fail. You can use
the fail() method for that.

https://docs.python.org/2/library/unittest.html#unittest.TestCase.fail


> (2) Why is the message  in the raise statement  i.e  raise
>  unittest.SkipTest("Class setup failed skipping test") not  getting
> displayed .


Raising a SkipTest exception is equivalent to calling the skipTest method,
which marks the test as an expected skipped test, not a failure. Since it
is not a failure, it doesn't display the exception.

If you run unittest in verbose mode, the skip message will be displayed. See
the documentation here:

https://docs.python.org/2/library/unittest.html#skipping-tests-and-expected-failures




-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.5.1 Not Working

2016-05-13 Thread John Gordon
In  Aidan Silcock 
 writes:

>   On Fri, 13 May, 2016 at 16:59, Aidan Silcock 
> wrote:
> Hello I have tried to download python 3.5.1 today and it has downloaded
> but each time I try to open it it says I need to Modify, Repair or
> Uninstall the program.I have tried repairing it neumerous times and it
> will say it was successful but then when I go to open it again it comes
> up with the same message.Can you help?Aidan

Hi Aidan,

Are you using Windows XP?  Unfortunately, versions of Python above 3.4.3
do not support Windows XP.  You'll have to download version 3.4.3 if you
are using Windows XP.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling python from C with OpenMP

2016-05-13 Thread Øystein Schønning-Johansen
On Friday, May 13, 2016 at 2:04:53 AM UTC+2, Sturla Molden wrote:
> You must own the GIL before you can safely use the Python C API, object
> creation and refcounting in particular. Use the "Simplified GIL API" to
> grab the GIL and release it when you are done.

I've now read about the GIL and it looks like I am in deep problems. 

I've added the GILState lock to the threaded loop like this:

#pragma omp parallel for
for( int i = 0; i < 10; i++ ){
PyGILState_STATE gstate;
gstate = PyGILState_Ensure();
PyObject *ret = PyObject_CallMethod( mult_obj, "do_multiply", "i", i );
if( !ret ){
printf("Cannot call 'do_multiply'\n");
continue;
}
printf("The value calculated in Python was: %3d\n", (int) 
PyLong_AsLong(ret));
Py_DECREF(ret);
PyGILState_Release(gstate);
}

 but still no success. Have I done it right?

regs,
-Øystein
-- 
https://mail.python.org/mailman/listinfo/python-list


How to put back a number-based index

2016-05-13 Thread David Shi via Python-list



 

 I lost my indexes after grouping in Pandas.
I managed to rest_index and got back the index column.
But How can I get back a index row?
Regards.
David

   
-- 
https://mail.python.org/mailman/listinfo/python-list


Skipping test using unittest SkipTest and exit status

2016-05-13 Thread Ganesh Pal
Hi Team,

Iam on  python 2.7 and Linux . I need inputs on the below  program  ,

Iam skipping the unittest  from setUpClass in following way  # raise
unittest.SkipTest(message)

The test are getting skipped but   I have two problem .

(1) This script  is in turn read by other  scripts  which considers the
test have passed based on the scripts return code , but the test have
actually been skipped   ,  How do include an exit status to indicates that
the test have failed

(2) Why is the message  in the raise statement  i.e  raise
 unittest.SkipTest("Class setup failed skipping test") not  getting
displayed .

Also thinking if we could replace raise  unittest.SkipTest with assert
statement ?


Sample code:

#!/usr/bin/env python
import unittest
import logging

class ScanTest(unittest.TestCase):

@classmethod
def setUpClass(self):
"""
Initial setup before unittest run
"""
pdb.set_trace()
self.scan = False
if not self.scan:
logging.error("Failed scanning ")
raise  unittest.SkipTest("Class setup failed skipping test")

self.data = True
if not self.data:
logging.error("Failed getting data ")
raise unittest.SkipTest("Class setup failed skipping test")
logging.info("SETUP.Done")

def test_01_inode_scanion(self):
"""  test01: inode scanion """
logging.info("### Executing test01:  ###")

@classmethod
def tearDownClass(self):
""" Cleanup all the data & logs """
logging.info("Cleaning all data")

def main():
""" ---MAIN--- """

try:
unittest.main()
except Exception as e:
logging.exception(e)
sys.exit(1)

if __name__ == '__main__':
main()

Sample output
gpal-ae9703e-1# python unitest1.py
ERROR:root:Failed scanning
s
--
Ran 0 tests in 0.000s

OK (skipped=1)

Regards,
Ganesh
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.5.1 Not Working

2016-05-13 Thread Aidan Silcock via Python-list


Sent from Yahoo Mail on Android 
 
  On Fri, 13 May, 2016 at 16:59, Aidan Silcock 
wrote:   HelloI have tried to download python 3.5.1 today and it has downloaded 
but each time I try to open it it says I need to Modify, Repair or Uninstall 
the program.I have tried repairing it neumerous times and it will say it was 
successful but then when I go to open it again it comes up with the same 
message.Can you help?Aidan  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An educational site written in Python (from YCombinator's RFS)

2016-05-13 Thread Cai Gengyang
My "vision" if you will for this site is one which should have these basic 
functionalities :

1) A forum for students , educators, parents and lawyers to post and discuss 
issues about education, fees, admissions process , visa issues.

2) A search engine for users to well (search for stuff lol)

2) Puzzles , Quizzes, Games and Tests in various topics. (Make it dynamic, 
animated and really interesting , I mean, I really love math, physics and 
engineering but a lot of lecturers are just fucking boring to listen to if you 
know what I mean. (makes you feel like you want to punch something. It would be 
great if every lecturer and professor in the world was as eloquent as 
Christopher Hitchens or as funny as Bill Maher, but especially in the hard 
sciences and math, alot of the lecturers are extremely smart but also very 
boring to listen to.

3) A live online discussion forum where users can discuss and chat see each 
other in real-time with a live video thingy (i don't know what its called) with 
some translator to help translate foreign accents and help users from different 
countries communicate properly. Imagine you are a poor genius amateur 
mathematician from Sudan who has just found a partial proof to the Riemann 
Hypothesis and you want to discuss it live in person over the internet with 
other math enthusiasts but can't speak English. A live translator that 
translates what you are speaking in real-time (if such a thing were possible, I 
have no idea) would be a good idea to create

4) A system to help parents connect with tutors whom they want to hire for 
their kids. I have no idea what the tutoring industry is like in other 
countries , but its a huge industry in Singapore with its super "kiasu" 
parents). There are already several such sites available, but I guess I could 
clone them and build them with different design (there can be infinite types of 
design, so its not like a zero-sum game). Especially as the population grows , 
there's likely to be more demand for these kind of sites and services. Alot of 
websites have very poor generic design and are unappealing to look at. 

edx.org is a great example , perhaps a competitor / clone with different 
functionalities and better design , more videos, graphics , more interactive 







On Wednesday, May 11, 2016 at 3:07:17 AM UTC+8, DFS wrote:
> On 5/10/2016 2:13 AM, Cai Gengyang wrote:
> > Ok, so after reading YCombinator's RFS, I have decided that I want to
> > work on this :
> >
> >
> > ---
> >
> >  EDUCATION
> >
> > If we can fix education, we can eventually do everything else on this
> > list. The first attempts to use technology to fix education have
> > focused on using the Internet to distribute traditional content to a
> > wider audience. This is good, but the Internet is a fundamentally
> > different medium and capable of much more.
> >
> > Solutions that combine the mass scale of technology with one-on-one
> > in-person interaction are particularly interesting to us.
> 
> one room, one teacher, one student, and one web browser?
> 
> 
> 
> > This may not require a "breakthrough" technology in the classical
> > sense, but at a minimum it will require very new ways of doing
> > things.
> >
> > ---
> >
> >  I want to create such a site using Python. What are the various
> > steps I need to take to create such a site ? This is a big project,
> > but one that is worth doing ... Any suggestions / help appreciated ?
> > Thanks alot
> 
> 
> When you say 'such a site' what do you envision?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Average calculation Program *need help*

2016-05-13 Thread Jake Kobs
Thank you so much! I finally got it. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fw: Question about issue with opening Python

2016-05-13 Thread Michael Torrie
On 05/13/2016 07:47 AM, christopher.amor...@mail.citytech.cuny.edu wrote:
> Hello,
> 
> Thank you for your reply. It says "IDLE's subprocess didn't make
> connection. Either IDLE can't start a subprocess or personal firewall
> software is blocking the connection." It worked after the first hour
> or so after downloading the program but now when I open it I keep
> getting this message. I've tried to turn off the firewall as well but
> still get this error message.

Have you tried googling for this error message? I did just now and one
of the top search results including several suggestions, including
making sure you haven't created python scripts and saved them in the
same directory as the python executable or IDLE itself.  If you do that,
and you happen to name your python program the same name as a built-in
module, it will prevent IDLE from loading.  If you have been saving any
python programs in the same directory as Python or IDLE, move them
somewhere else.

Just a shot in the dark. could be way off base.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fw: Question about issue with opening Python

2016-05-13 Thread Michael Torrie
On 05/13/2016 07:05 AM, christopher.amor...@mail.citytech.cuny.edu wrote:
> I downloaded an older version of Python and for about an hour it was
> working, but started to get the same error message I received when
> using the latest version of Python.

You'll have to tells us what the error was that you are seeing.
Attachments are not allowed on this list, so you'll have to type it, or
if you can, copy and paste the exact error.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fw: Question about issue with opening Python

2016-05-13 Thread Steven D'Aprano
On Fri, 13 May 2016 11:05 pm, christopher.amor...@mail.citytech.cuny.edu
wrote:

> I downloaded an older version of Python and for about an hour it was
> working, but started to get the same error message I received when using
> the latest version of Python.

Do you have a question, or are you just sharing?

Is the error message a secret, or should we guess what it is? My guess is:

+++ OUT OF CUCUMBERS ERROR +++ REBOOT UNIVERSE +++

Am I close?

If not, then you should copy and paste the error message. Please don't send
a screen shot: this is a text only newsgroup, and attachments will be
automatically deleted. Also, some people reading these messages may be
fully or partially blind, and while their screen reader software will work
fine with text, a screen shot is useless for them.

If you absolutely must use a screen shot, because the error cannot be copied
and is too long to retype, then please post it as a link to imgurl:

https://imgur.com/




-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fw: Question about issue with opening Python

2016-05-13 Thread Bob Gailer
On May 13, 2016 9:22 AM, "christopher.amor...@mail.citytech.cuny.edu" <
christopher.amor...@mail.citytech.cuny.edu> wrote:
>
>
>
>
>
> 
> From: christopher.amor...@mail.citytech.cuny.edu
> Sent: Thursday, May 12, 2016 7:35 PM
> To: python-list@python.org
> Subject: Fw: Question about issue with opening Python
>
>
>
> I downloaded an older version of Python and for about an hour it was
working, but started to get the same error message I received when using
the latest version of Python.

This mailing list does not take attachments. Please copy and paste the
error into a reply.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fw: Question about issue with opening Python

2016-05-13 Thread christopher.amor...@mail.citytech.cuny.edu





From: christopher.amor...@mail.citytech.cuny.edu
Sent: Thursday, May 12, 2016 7:35 PM
To: python-list@python.org
Subject: Fw: Question about issue with opening Python



I downloaded an older version of Python and for about an hour it was working, 
but started to get the same error message I received when using the latest 
version of Python.



From: christopher.amor...@mail.citytech.cuny.edu
Sent: Thursday, May 12, 2016 10:36 AM
To: python-list@python.org
Subject: Question about issue with opening Python



Hello,


I downloaded Python a few days ago and was using without any issues until 
yesterday. Every time I try to open the IDLE I get an error message that you 
can see the attachment. I tried to reinstall it but still get the same message. 
If there's any way you could help it would be greatly appreciated. Thank you.


-Christopher
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Distinction between “class” and “type”

2016-05-13 Thread Gregory Ewing

Paul Rubin wrote:

You can't instantiate T by saying

   x = T()

and expecting to get back some value that is (indeterminately) an int or
a string.


Unless it's Python 6000 running on a quantum computer...

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Design: Idiom for classes and methods that are customizable by the user?

2016-05-13 Thread dieter
Dirk Bächle  writes:
> ...
> My questions
> 
>
> - Is this a good approach, that I could use for other parts of the 
> architecture as well, e.g. the Node class mentioned above?

You might look at the "adpater" pattern.

It is heavily used in Zope - and there looks something like:

  * components are abstracted by interfaces (--> "zope.interface")

  * where flexibility is needed, the code looks like

  component = queryAdapter(, interface, default=...)

or

  component = queryUtility(interface, default=...)

to get a component implementing "interface".

(utilities are in some way adapters for "None", i.e.
those independent of a context)

  * there is an adapter registry, 
its content is specified either via an XML specification file
or via Python code


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Average calculation Program *need help*

2016-05-13 Thread Nick Sarbicki
On Fri, 13 May 2016, 06:52 Jake Kobs,  wrote:

> Thank you for the help..I think I'm getting closer, but I feel like after
> they enter an invalid number, it should reset the invalid number(s)
> somehow. Here's my updated code:
>
> --
> #this function will get the total scores
> def getScores(totalScores, number):
> for counter in range(0, number):
> score = input('Enter their score: ')
> if (score < 100 and score > 0):
> totalScores = totalScores + score
> while (score > 100 or score < 0):
>
> print "Your scores must be between 0 and 100."
> score = input('Enter their score: ')
> score = input('Enter their score: ')
> totalScores = totalScores + score
>
>
> return totalScores
>
> 
> --
>

You're starting to get it which is good.

The if is a good idea to begin with, but your while loop still executes
after the for loop finishes as it is not properly indented.

As Michael said, indentation indicates what statement has ownership of a
block. Currently your while loop has it's own block outside the for loop.

This means it gets executed after your for loop has finished looping
through your range. You want the while to be held within the for loop so it
gets executed immediately after each input statement.

Think. Your if is inside the for loop and gets executed after every input.
Your input is inside the for loop. Your while and it's contents are not in
the for loop and get executed after the for loop finishes. The only
difference that matters here is indentation.

Try solve that bit first.

>
-- 
https://mail.python.org/mailman/listinfo/python-list