Install a package:

try:
    import zumba
except ImportError:
    import pip
    pip.main(['install', '--user', 'zumba'])
    import zumba

Very useful materials:

 https://www.shanelynn.ie/summarising-aggregation-and-grouping-data-in-python-pandas/

 

Plots

https://pandas.pydata.org/pandas-docs/stable/visualization.html

 


'''
Created on Jul 15, 2017

@author: manicbird
'''
import networkx as nx
import matplotlib.pylab as plt
import itertools as it
import random
def draw_circle_around_clique(clique,coords):
    dist=0
    temp_dist=0
    center=[0 for i in range(2)]
    color=next(colors)
    for a in clique:
        for b in clique:
            temp_dist=(coords[a][0]-coords[b][0])**2+(coords[a][1]-coords[b][1])**2
            if temp_dist>dist:
                dist=temp_dist
                for i in range(2):
                    center[i]=(coords[a][i]+coords[b][i])/2
    rad=dist**0.5/2
    cir = plt.Circle((center[0],center[1]), radius=rad*1.3,fill=False,color=color,hatch=next(hatches))
    plt.gca().add_patch(cir)
    plt.axis('scaled')
    # return color of the circle, to use it as the color for vertices of the cliques
    return color

global colors, hatches
colors=it.cycle('bgrcmyk')# blue, green, red, ...
hatches=it.cycle('/\|-+*')


no = 36
# create a random graph
G=nx.gnp_random_graph(n=no,p=0.4)
# remember the coordinates of the vertices
#coords=nx.spring_layout(G)
coords=nx.circular_layout(G)



fig = plt.figure()
#draw the graph
nx.draw(G,pos=coords,edge_color='blue',node_color='red', with_labels=True,font_color='black')
fig.savefig('/home/manicbird/Dropbox/EclipseWorkSpace/fig'+str(no)+'.png')


subG = random.sample(range(no),12)
print(type(subG))
nodeshapes='so^>v<dph8'
nx.draw_networkx_nodes(G.subgraph(subG), pos=coords, node_color='red', linewidths=3, node_shape='<')
nx.draw_networkx_edges(G.subgraph(subG), pos=coords, edge_color='black', width=3)


drawCliques = False

if drawCliques:
    # remove "len(clique)>2" if you're interested in maxcliques with 2 edges
    cliques=[clique for clique in nx.find_cliques(G) if len(clique)>2]

    k=[len(x) for x in cliques]
    counter=0
    for clique in cliques:
        
        if (k[counter]==max(k)):
            
            print ("Clique length to appear: {} ".format(len(clique)))
            nx.draw_networkx_nodes(G.subgraph(clique), pos=coords, node_color='blue')
            nx.draw_networkx_edges(G.subgraph(clique), pos=coords, edge_color='black', width=2)
            break
            #nx.draw_networkx_nodes(G,pos=coords,nodelist=clique,node_color=draw_circle_around_clique(clique,coords))
        counter += 1
plt.show()
fig.savefig('/home/manicbird/Dropbox/EclipseWorkSpace/fig'+str(no)+'clique.png')
if __name__ == '__main__':
    pass 

 


networkx clique

import data

To export data from a pandas.dataframe tp sqlite one can use the following code:

import pandas
import scipy
  1. import pandas as pd
  2. import sqlite3
  3. dbFullPath = "D:\\Dropbox\\Python\\machineLearning.sqlite"
  4. conn = sqlite3.connect(dbFullPath)
  5. coverData.to_sql('covers' , con= conn, if_exists='replace')

To use sqlite commands:

  1. with conn:
  2. cnx = conn.cursor()
  3. cnx.execute("SELECT name FROM sqlite_master WHERE type='table';")
  4. print(cnx.fetchall())
  5.  
  6.     cnx.execute("SELECT name FROM sqlite_master")
  7. print(cnx.fetchall())

The following section and two tables are taken from "http://pandas.pydata.org/pandas-docs/stable/indexing.html"

.loc, .iloc, .ix and also [] indexing can accept a callable as indexer. See more at Selection By Callable.

Getting values from an object with multi-axes selection uses the following notation (using .loc as an example, but applies to .iloc and .ix as well). Any of the axes accessors may be the null slice :. Axes left out of the specification are assumed to be :. (e.g. p.loc['a'] is equiv to p.loc['a', :, :])

Object Type Indexers
Series s.loc[indexer]
DataFrame df.loc[row_indexer,column_indexer]
Panel p.loc[item_indexer,major_indexer,minor_indexer]

Basics

As mentioned when introducing the data structures in the last section, the primary function of indexing with [] (a.k.a. __getitem__ for those familiar with implementing class behavior in Python) is selecting out lower-dimensional slices. Thus,

Object Type Selection Return Value Type
Series series[label] scalar value
DataFrame frame[colname] Series corresponding to colname
Panel panel[itemname] DataFrame corresponding to the itemname

 If a column in a dataframe contains classes or factors we can extract data corresponding a subset of these classes or factors as following:

 

subgroups

Your text...