Skip to content

Instantly share code, notes, and snippets.

View infinite-Joy's full-sized avatar

Joydeep Bhattacharjee infinite-Joy

View GitHub Profile
print('Dropping the non relevant fields')
print('Shape before dropping the fields {}'.format(df_state.shape))
df_state = df_state.drop(df_state.index[df_state.State == 'Total (All India)'])
df_state = df_state.drop(df_state.index[df_state.State == 'Total (States)'])
df_state = df_state.drop(df_state.index[df_state.State == 'Total (Uts)'])
print('Shape after dropping the fields {}'.format(df_state.shape))
# Groupby states
df_state = df.drop('Year', axis=1)
df_state = df_state.groupby('State', as_index=False).agg({'Total': 'sum'})
print(df_state.head())
import pandas as pd
data = "./suicides.csv"
df = pd.read_csv(data)
print(df.head())
%matplotlib inline
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
import pylab
# initialise a directed graph
G = nx.DiGraph()
graph = {'a': {'w': 14, 'x': 7, 'y': 9},
'b': {'w': 9, 'z': 6},
'w': {'a': 14, 'b': 9, 'y': 2},
'x': {'a': 7, 'y': 10, 'z': 15},
'y': {'a': 9, 'w': 2, 'x': 10, 'z': 11},
'z': {'b': 6, 'x': 15, 'y': 11}}
findapath(X, Y, W, [X,Y], _) :- edge(X, Y, W). % findapath between X and Y has weight W if there is an edge between X and Y of weight W
findapath(X, Y, W, [X|P], V) :- % else findapath between X and Y
\+ member(X, V), % is true
edge(X, Z, W1), % if we can findapath between X and Z with weight W1
findapath(Z, Y, W2, P, [X|V]), % and there is findapat between Z and Y of weight W2
W is W1 + W2. % where W is W1 + W2
:-dynamic(solution/2).
findminpath(X, Y, W, P) :-
\+ solution(_, _),
edge(a,w,14).
edge(a,x,7).
edge(a,y,9).
edge(b,w,9).
edge(b,z,6).
edge(w,a,14).
edge(w,b,9).
edge(w,y,2).
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
main :-
has(X,apples), % who has apples
has(Y,plums), % who has plums
write(X), % write the apple lovers
put(10), % new line
write(Y), % write the plum lovers
nl, halt. % new line and halt
main :-
listing(fruit), nl, halt.