Monday, 28 September 2020

How to convert a pandas dataframe into list of dictionaries ?

 Pandas is a high-level data manipulation tool commonly used in python. It is build on Numpy and the key data structure is DataFrame.

Here I am explaining a sample python program to convert a Pandas Dataframe into a list of dictionaries.

Program to convert Dataframe into list of dictionaries

In the below program, we are reading a csv file and loading it in pandas. You can configure the delimiter as per your requirement. The required_fields is an optional parameter that can be used to limit or select the required fields in the Dataframe from the csv. By default, it picks up all the fields in the file.

Sunday, 27 September 2020

Python Program to Split a large list into list of smaller lists

There are requirements where we have to split a large list into a set of smaller lists. This is a common requirement in places where we use parallel processing. Here is a sample program in python to split a larger list into a set of smaller lists.

 


Simple LED blinking circuit using Raspberry Pi and Python

Introduction

Raspberry Pi is one of the powerful device invented in this era. During my school days and college days, all the automation circuits and hobby circuits were developed  either directly by soldering components in the generic circuit board or by using a micro controllers like Arduino. The set up and debug effort was more and the programming was limited to Arduino processing language.

With the invention of Raspberry Pi, the possibilities are endless. It is a mini computer with all the facilities of a desktop PC. Users can develop and run any programs as they wish. The device also comes with options to connect to several peripherals and extension circuit boards.

Here I will be explaining a very simple program, like the baby step towards the world of automation using Raspberry Pi. We will use Raspberry Pi to control an LED (Turn OFF and ON).

Requirements

  •  Raspberry Pi
  • SD Card with Raspbian OS
  • Bread Board
  • Jumper wires
  • LED (2 nos)

GPIO Pins in Raspberry Pi 

A powerful feature of the Raspberry Pi is the row of GPIO (general-purpose input/output) pins along the top edge of the board. Any of the GPIO pins can be designated (in software) as an input or output pin and used for a wide range of purposes. In this example, we are using a python program to control the GPIO pins and turn ON/OFF LED.

Connection

Connect negative leg of both LED to PIN 6(Ground), one positive leg to PIN 8 and another positive LEG to PIN 10

Program

Raspbian OS will be having Thonny Python IDE by default, so it’s easy to write and execute python codes in Raspberry Pi 
 
Install the RPi.GPIO package in the Raspberry Pi. 
 
       
       pip install RPi.GPIO

 
Copy paste the below program in the IDE. Make the connections between LED and GPIO pins as explained in the previous step.
 

Execute the program. You will see the lights blinking.



 


How to check the memory utilization of cluster nodes in a Kubernetes Cluster ?

 The memory and CPU utilization of a Kubernetes cluster can be checked by using the following command. kubectl top nodes The above command...