This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| data = "./suicides.csv" | |
| df = pd.read_csv(data) | |
| print(df.head()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %matplotlib inline | |
| import networkx as nx | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import pylab | |
| # initialise a directed graph | |
| G = nx.DiGraph() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(_, _), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| main :- | |
| listing(fruit), nl, halt. |