Wednesday, 9 November 2016

Connect Python and Arduino

Hi All,

Use the steps below.

At First Run Arduino and select COM3 as port

with LDR Program
------------------------------------------------------------------------------
const int ldr = 0;    //A0 assigned as LDR pin.
int value = 0;        //Store values from LDR.

void setup()
{
  Serial.begin(9600);   //Fix serial baud rate at 9600bps
}

void loop()
{
  value = analogRead(ldr);    //Read the analog values from LDR. or simply use value=999
  Serial.println(value);      //Print to serial monitor.
  delay(250);                 //Delay of 250 milliseconds (1/4th of a second).
}

------------------------------------------------------------------------------
Then in the Python
install serial first.
then type this command

------------------------------------------------------------------------------

import time;
ser = serial.Serial('COM3', 9600, timeout=0,parity=serial.PARITY_EVEN, rtscts=1)
while True:
s=ser.read();
print(s);
time.sleep(3);
------------------------------------------------------------------------------

Friday, 4 November 2016

Data Mining using Python

Hi All,
The main purpose of learning Python is Data Mining.
The advantages are many fold.
1. Identify patterns
2. Commercialize the tools
3. Development of commercial business tools
4. Training Data Science
5. Come out with new data mining tools.

The list is endless.
To start with we can go for 'pandas' package from the site given below.

                 http://pandas.pydata.org/getpandas.html

To configure the same, we can use the below given link.

                 http://pandas.pydata.org/pandas-docs/stable/install.html

All the best to become a data scientist.

Appending List

 HI,

See how to append a list using squares

-------------------------------------------------------------

items = [2, 3, 4, 5, 6]
squares = []
for x in items:
 squares.append(x ** 2)
print squares

-------------------------------------------------------------

Wednesday, 2 November 2016

Lists in Python

Hi All,

Lists are some kinds of advanced arrays.

list.py

----------------------------------------------------------------------------
student=['Rajeev','Kollam',1977,39]
print student[0:3]
----------------------------------------------------------------------------

Run this program.
This will display elements from index '0 to '3'

Some help hints about list
1. del list[1] - remove item in the position '1'
2. len(list) - give you the size of list
3.list=list*2 - append the same list at the end

Try more

 

Loop and if in Python

Hi All,

See a program to print event numbers from 1 to 8

loop.py
---------------------------------------------------------------------------------------
print 'Displaying even numbers from 1 to 8'
for i in range(1,9):
 if i%2==0:   
  print i

---------------------------------------------------------------------------------------

Then type the command : python loop.py  


 gurst@dell:~$ python loop.py

NB: See the spaces in front of 'if statment' and 'print i'. 

 
Assignments

1. Factorial
2. Prime number checking
3. Sum of Series
4. Nested loop for a patter like this

*
* *
* * *
* * * *
* * * * * 

Add two numbers

Hi All,

we will start from basics.

Qn) Read two numbers, find sum and display output.

first.py
---------------------------------------------------------------------------------------
print("Enter two numbers")
n1=input("First Number")
n2=input("Second Number")
print 'sum of', n1, 'and',n2, 'is ', n1+n2
---------------------------------------------------------------------------------------
Save this file as first.py


Now come to command prompt and come to your folder.
Type 'ls' to check whether your file first.py is in your present working directory
Then type the command : python first.py  


 gurst@dell:~$ python first.py

Now see the output


Why Python

Hi All,

Python is so popular these days, as they are approached for Data mining, Data analytics, Image processing, Scientific programming, IoT etc,

They have got powerful packages for all kinds of data processing.

We will see more on that soon.