def on_changed(self, widget):
        #data = pd.read_csv("/home/prasadgadde/Documents/BigData/Project/crime-in-india/crime/01_District_wise_crimes_committed_IPC_2013.csv"
        district = s(self.data[
            self.data['STATEorUT'] == widget.get_active_text()].filter(
                items=['DISTRICT'])['DISTRICT']).unique().tolist()
        self.store_dist.clear()
        self.store_dist.append(["All"])
        for i in district:
            self.store_dist.append([i])

        self.combobox_district.set_model(self.store_dist)
        #combobox.connect('changed', self.on_changed)
        self.combobox_district.set_active(0)
Пример #2
0
#!/usr/bin/python
from pandas import Series as s
from pandas import DataFrame as f
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
s1=s(range(1,6))
s1.index='one two three four five'.split()
so=s1.plot(kind='bar',rot=90)
so.set_xticks(range(5))#will not work
so.set_xticklabels='aa bb cc dd ee'.split()#will not work
print s1
plt.show()
Пример #3
0
import pandas
from pandas import Series as s
from pandas import DataFrame as df
ser = s('1000,1200,9000,9500,9750'.split(","))
ser.name = 'NAME'
sdf = df(ser)
print sdf
Пример #4
0
#!/usr/bin/python
from pandas import Series as s
from pandas import DataFrame as f
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
s1 = s(range(1, 10))
s1.plot()
plt.show()
    def __init__(self):
        super(PyApp, self).__init__()

        self.set_title("Crimes in India")
        self.set_size_request(700, 500)
        #self.set_icon_from_file("/home/prasadgadde/Documents/BigData/Project/icon.png")

        # Set window background image
        pixbuf = gtk.gdk.pixbuf_new_from_file(
            "vector-grunge-texture-background.jpg")
        pixmap, mask = pixbuf.render_pixmap_and_mask()
        width, height = pixmap.get_size()
        #del pixbuf
        self.set_app_paintable(gtk.TRUE)
        self.resize(width, height)
        self.realize()
        self.window.set_back_pixmap(pixmap, gtk.FALSE)
        #del pixmap

        nb = gtk.Notebook()
        nb.set_tab_pos(gtk.POS_TOP)
        vbox = gtk.VBox(False, 5)

        vb = gtk.VBox()
        hbox = gtk.HBox(True, 3)
        hlabelsbox = gtk.HBox(True, 120)
        hbuttonbox = gtk.HBox(True, 10)

        # Horizontal box for labels
        label_state = gtk.Label("State")
        label_district = gtk.Label("District")
        label_year = gtk.Label("Year")
        label_crime = gtk.Label("Crime")

        hlabelsbox.pack_start(label_state, True, True, 10)
        hlabelsbox.pack_start(label_district, True, True, 10)
        hlabelsbox.pack_start(label_year, True, True, 10)
        hlabelsbox.pack_start(label_crime, True, True, 10)

        valign = gtk.Alignment(0.25, 0.10, 0, 0)
        valign1 = gtk.Alignment(0, 1, 0, 0)
        valign2 = gtk.Alignment(0, 0, 1, 0)

        store = gtk.ListStore(str)
        cell = gtk.CellRendererText()
        self.combobox_state.pack_start(cell)
        self.combobox_state.set_title("States")
        self.combobox_state.add_attribute(cell, 'text', 0)

        hbox.pack_start(self.combobox_state, True, True, 10)

        store.append(["ANDHRA PRADESH"])
        store.append(["ARUNACHAL PRADESH"])
        store.append(["ASSAM"])
        store.append(["BIHAR"])
        store.append(["GOA"])
        store.append(["GUJARAT"])
        store.append(["HARYANA"])
        store.append(["HIMACHAL PRADESH"])
        store.append(["JAMMU & KASHMIR"])
        store.append(["JHARKHAND"])
        store.append(["KARNATAKA"])
        store.append(["KERALA"])
        store.append(["MADHYA PRADESH"])
        store.append(["MAHARASHTRA"])
        store.append(["MANIPUR"])
        store.append(["MEGHALAYA"])
        store.append(["MIZORAM"])
        store.append(["NAGALAND"])
        store.append(["ODISHA"])
        store.append(["MIZORAM"])
        store.append(["PUNJAB"])
        store.append(["RAJASTHAN"])
        store.append(["TAMIL NADU"])
        store.append(["TRIPURA"])
        store.append(["UTTAR PRADESH"])
        store.append(["UTTARAKHAND"])
        store.append(["WEST BENGAL"])
        store.append(["A & N ISLANDS"])
        store.append(["CHANDIGARH"])
        store.append(["D & N HAVELI"])
        store.append(["DAMAN & DIU"])
        store.append(["DELHI UT"])
        store.append(["LAKSHADWEEP"])
        store.append(["PUDUCHERRY"])

        self.combobox_state.set_model(store)
        self.combobox_state.connect('changed', self.on_changed)
        self.combobox_state.set_active(0)

        self.store_dist = gtk.ListStore(str)
        cell_dist = gtk.CellRendererText()
        self.combobox_district.pack_start(cell_dist)
        self.combobox_district.add_attribute(cell_dist, 'text', 0)
        self.combobox_district.connect('changed', self.on_changed_district)
        hbox.pack_start(self.combobox_district, True, True, 10)

        #Year dropbox

        store_year = gtk.ListStore(str)
        cell_year = gtk.CellRendererText()
        self.combobox_year.pack_start(cell_year)
        self.combobox_year.add_attribute(cell_year, 'text', 0)

        hbox.pack_start(self.combobox_year, True, True, 10)

        district = self.data[(self.data['STATEorUT'] == 'ANDHRA PRADESH') | (
            self.data['STATEorUT'] == 'Andhra Pradesh')].filter(
                items=['STATE/UT', 'DISTRICT', 'YEAR'])
        year = s(district['YEAR']).unique().tolist()
        store_year.append(["All"])
        for i in year:
            store_year.append([i])

        self.combobox_year.set_model(store_year)
        #combobox.connect('changed', self.on_changed)
        self.combobox_year.set_active(0)
        self.combobox_year.connect('changed', self.on_changed_year)

        # Crime dropbox

        store_crime = gtk.ListStore(str)
        cell_crime = gtk.CellRendererText()
        self.combobox_crime.pack_start(cell_crime)
        self.combobox_crime.add_attribute(cell_crime, 'text', 0)
        self.combobox_crime.connect('changed', self.on_changed_crime)

        hbox.pack_start(self.combobox_crime, True, True, 10)

        store_crime.append(["MURDER"])
        store_crime.append(["RAPE"])
        store_crime.append(["KIDNAPPING"])
        store_crime.append(["RIOTS"])
        store_crime.append(["ROBBERY"])
        store_crime.append(["BURGLARY"])
        store_crime.append(["DOWRY DEATHS"])
        store_crime.append(["TOTAL IPC CRIMES"])
        self.combobox_crime.set_model(store_crime)
        #combobox.connect('changed', self.on_changed)
        self.combobox_crime.set_active(0)

        valign.add(hbox)
        valign1.add(hlabelsbox)

        button_disp_data = gtk.Button("Display Data")

        button_disp_data.connect("clicked", self.display_data)
        self.button_show_graph.connect("clicked", self.display_graph)

        self.button_show_graph.set_sensitive(False)

        hbuttonbox.pack_start(button_disp_data, True, True, 10)
        hbuttonbox.pack_start(self.button_show_graph, True, True, 10)
        valign2.add(hbuttonbox)
        vbox.pack_start(valign1)
        vbox.pack_start(valign)
        vbox.pack_start(valign2)

        nb.append_page(vbox)
        nb.set_tab_label_text(vbox, "District wise crimes")

        # Code for 2nd TAB

        state1lbl = gtk.Label("State 1")
        state2lbl = gtk.Label("State 2")

        self.compare_button.connect("clicked", self.compare_states)
        self.compare_button.set_sensitive(False)

        table = gtk.Table(8, 4, True)
        table.set_col_spacings(7)

        states = [
            "ANDHRA PRADESH", "ARUNACHAL PRADESH", "ASSAM", "BIHAR",
            "CHHATTISGARH", "GOA", "GUJARAT", "HARYANA", "HIMACHAL PRADESH",
            "JAMMU & KASHMIR", "JHARKHAND", "KARNATAKA", "KERALA",
            "MADHYA PRADESH", "MAHARASHTRA", "MANIPUR", "MEGHALAYA", "MIZORAM",
            "NAGALAND", "ODISHA", "PUNJAB", "RAJASTHAN", "SIKKIM",
            "TAMIL NADU", "TRIPURA", "UTTAR PRADESH", "UTTARAKHAND",
            "WEST BENGAL", "A & N ISLANDS", "CHANDIGARH", "D & N HAVELI",
            "DAMAN & DIU", "DELHI UT", "LAKSHADWEEP", "PUDUCHERRY"
        ]
        storestate1 = gtk.ListStore(str)
        cellstate1 = gtk.CellRendererText()
        self.combobox_state1.pack_start(cellstate1)
        self.combobox_state1.add_attribute(cellstate1, 'text', 0)
        self.combobox_state1.set_active(0)
        for i in states:
            storestate1.append([i])
        self.combobox_state1.set_model(storestate1)

        storestate2 = gtk.ListStore(str)
        cellstate2 = gtk.CellRendererText()
        self.combobox_state2.pack_start(cellstate2)
        self.combobox_state2.add_attribute(cellstate2, 'text', 0)
        self.combobox_state2.set_active(0)
        for i in states:
            storestate2.append([i])
        self.combobox_state2.set_model(storestate2)

        store_yearc = gtk.ListStore(str)
        cell_yearc = gtk.CellRendererText()
        self.combobox_yearc.pack_start(cell_yearc)
        self.combobox_yearc.add_attribute(cell_yearc, 'text', 0)
        self.combobox_yearc.set_active(0)

        for i in year:
            store_yearc.append([i])
        self.combobox_yearc.set_model(store_yearc)

        self.combobox_state1.connect('changed', self.on_changed_state1)
        self.combobox_state2.connect('changed', self.on_changed_state2)
        self.combobox_yearc.connect('changed', self.on_changed_yearc)

        table.attach(state1lbl, 0, 1, 3, 4)
        table.attach(state2lbl, 2, 3, 3, 4)
        table.attach(self.combobox_state1, 0, 1, 4, 5, xpadding=8, ypadding=9)
        table.attach(self.combobox_state2, 2, 3, 4, 5, xpadding=8, ypadding=9)
        table.attach(self.combobox_yearc, 1, 2, 4, 5, xpadding=8, ypadding=9)
        table.attach(self.compare_button, 1, 2, 6, 7, xpadding=8, ypadding=9)

        nb.append_page(table)
        nb.set_tab_label_text(table, "Comparison of states")

        tv = gtk.TextView()
        nb.append_page(tv)
        nb.set_tab_label_text(tv, "About")

        self.add(nb)

        self.connect("destroy", gtk.main_quit)
        self.show_all()
Пример #6
0
#!/usr/bin/python
from pandas import Series as s
from pandas import DataFrame as f
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
s1=s([.3,.22,.2])
s1.name='Halfs'
s1.index='one two three'.split()
so=s1.plot(kind='pie',autopct='%22.2f')
print s1
plt.show()
Пример #7
0
from pandas import DataFrame as f
from pandas import Series as s

#Question 1  Create a (4,4)2D array  consisting of integers.
a = np.array(range(1, 17)).reshape(4, 4)

#Question 2  Create a masked array from the above array by making numbers which are divisible by 3 as invalid values.
mska = np.ma.masked_array(a, mask=a % 3 == 0)
print mska.mask, "\n"

#Question 3  Create a dataframe from the above masked array.
dfma = f(mska)
print dfma, "\n"

#Question 4  Create a series of your own choice and do reindexing by exploring ffill,bfill,nearest etc
s1 = s(range(4), index=list("abcd"))
print s1, "\n"
print s1.reindex(list("abcde")), "\n"
print s1.reindex(list("abcde"), method="ffill"), "\n"
print s1.reindex(list("abcde"), method="bfill"), "\n"
#print s1.reindex(list("abecd"),method="nearest"),"\n"

#Question 5  Create a Dataframe object of your own choice and do reindexing.
ad = np.arange(1, 10).reshape(3, 3)
df1 = f(ad, columns=list("abc"), index=list("xyz"))
print df1, "\n"
print df1.reindex(list("yzx")), "\n"

#Question 6  Create a dataframe object from the above array by making c1,c2,c3,c4 as column indices and r1,r2,r3,r4 as row indices.
a1 = np.array(range(1, 17)).reshape(4, 4)
df2 = f(a1, index="r1 r2 r3 r4".split(), columns="c1 c2 c3 c4".split())
Пример #8
0
import pandas as pd
from pandas import Series as s
from pandas import DataFrame as d
import numpy as np
d1 = {'Name': ['Everest', 'K2', 'Kilimajaro'], 'Height': [8, 7.5, 6.5]}
df1 = d(d1)
print df1, "\n"

df1['rank'] = 0
print df1, "\n"

s1 = s(list('abcd'))
print s1, "\n"
df2 = d(s1)
print df2, "\n"

a = np.array(range(15)).reshape((3, 5))
df3 = d(a, index="r1 r2 r3".split(), columns="c1 c2 c3 c4 c5".split())
print df3, "\n"

d2 = {
    'E_Name': {
        'E1': 'Varun',
        'E2': 'Akshay',
        'E3': 'Tom'
    },
    'Eno': {
        'E1': 104,
        'E2': 105,
        'E3': 106
    }
Пример #9
0
dic1={ 'student':['S1','S2','S3'],\
'studid':[199,198,120],\
'marks':[78,88,80] }

dataframe1 = df(dic1, columns=['student', 'studid', 'marks'])
print dataframe1

dataframe1 = df(dic1, columns=['student', 'studid', 'marks', 'dept'])
print dataframe1
#dataframe1.fillna(0)
dataframe1['dept'] = ['sci', 'mat', 'bio']
print dataframe1

#4.create a dataframe obj from a series obj of your own choice.
l1 = np.arange(6, 20)
ser1 = s(l1)
df2 = df(ser1, columns=['ADF'])
print df2

#5.create a dataframe obj from the above series obj(Qno.4) after assigning a value for name attribute.
ser1.name = 'NAMESERIES'
df3 = df(ser1)
print df3

#6.create a dataframe object from a numpy 2D array by giving values for columns and index of your own choice.

l1 = np.arange(1, 10).reshape(3, 3)
df6 = df(l1, index=list('abc'), columns=['x', 'y', 'z'])
print df6

#7.create a nested dictionary to store employee details like empno,empname and salary.create a dataframe from this dict
Пример #10
0
	4.print all the elements
	5.print first two elements
	6.create another series object by supplying string labels as index
	7.print all the elements/print individual elements
	8.create a dict object and then  a series object from that dictionary  
	9.create another dict obj with some common keys (Q.No.8) and then a series obj
	10.add the two Series objs and print the result.
	"""
import pandas as pd
from pandas import Series as s
import numpy as np

print pd.__version__, "\n"

l1 = np.arange(1, 6)
s1 = s(l1)
print s1
print s1[[0, 1]]

l2 = np.arange(6, 11)
s2 = s(l2, index=list('abcde'))
print s2.values

d1 = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
s3 = s(d1)
print s3.values

d2 = {'a': 11, 'z': 22, 'y': 33, 'k': 44}
s4 = s(d2)
print s4.values