Skip navigation

Monthly Archives: Maret 2014


I imported a CSV in pandas like below

>>> import pandas
>>> df = pandas.read_csv('file.csv',names=['count', 'province', 'city', 'district', 'region', 'area'])
>>> df.head()
   count province         city           district region area
0   7923     Aceh   Aceh Barat   Arongan Lambalek            
1    628     Aceh   Aceh Barat     Johan Pahlawan            
2    235     Aceh   Aceh Barat        Woyla Timur            
4   3900     Aceh   Banda Aceh                         

using SQL, I can do something like this

    SELECT SUM(count) AS sum, district 
        FROM table WHERE city = 'Aceh Barat' 
        GROUP BY district 
        ORDER BY sum DESC

but using pandas python library, I can achieve the same using.

>>> import pandas, numpy
>>> df = pandas.read_csv('file.csv',names=['count', 'province', 'city', 'district', 'region', 'area'])
>>> df[df['city'] == 'Aceh Barat'].groupby('district').aggregate(numpy.sum).sort(['count'], ascending=False)
                  count
district               
Arongan Lambalek   7923
Johan Pahlawan      628
Woyla Timur         235

>>> df[df['city'] == 'Aceh Barat'].groupby('district').aggregate(numpy.sum).sort(['count'], ascending=False)
                  count
district               
Arongan Lambalek   7923
Johan Pahlawan      628
Woyla Timur         235

>>> df[df['city'] == 'Medan']
        count        province   city            district region area
10340  108769  Sumatera Utara  Medan                 NaN    NaN  NaN
10341     759  Sumatera Utara  Medan        Medan Amplas    NaN  NaN
10342     579  Sumatera Utara  Medan        Medan Amplas    NaN  NaN
10343    1272  Sumatera Utara  Medan        Medan Amplas    NaN  NaN
10344     769  Sumatera Utara  Medan        Medan Amplas    NaN  NaN
10345     379  Sumatera Utara  Medan        Medan Amplas    NaN  NaN
10346     988  Sumatera Utara  Medan        Medan Amplas    NaN  NaN
10347    4395  Sumatera Utara  Medan          Medan Area    NaN  NaN
10348    5598  Sumatera Utara  Medan         Medan Barat    NaN  NaN

>>> df[df['city'] == 'Medan'].groupby('district').aggregate(numpy.sum).sort(['count'], ascending=False)
                    count
district                 
Medan Tuntungan      7425
Medan Tembung        6349
Medan Barat          5598
Medan Timur          5378
Medan Amplas         4746

Just a simple trick I did today.

Basically I want to remove the circle button in the radio button and use the label as the choice for the button.

So instead of having this

Screenshot from 2014-03-06 13:21:31

I want to have this

Screenshot from 2014-03-06 13:21:45

I can do this just using CSS without Javascript. Here’s the JS Fiddle.

http://jsfiddle.net/petrabarus/pPgS7/

 

%d blogger menyukai ini: