“Hello world” using python in Red hat

Before installing python on the Linux platform, you may have to install zlib package,

$ yum install zlib-devel

if any permission issue, then 
$ sudo yum install zlib-devel
Download python releases from python.org, you can choose the release version according to your need

$ wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
unzip the downloaded file using the following command
$ tar xf Python-3.8.6.tgz
Change the directory to python directory

 $ cd Python-3.*
run the ./configure tool to prepare the build
$ run the ./configure tool to prepare the build
now using make command , start to build python
$ make
finally you can install python using the below command,
$ make install

if you face any permission issue, then use sudo

$ sudo make install

If you need to run multiple python releases in your platform, you have to use the below command, so it will not overwrite the existing python release
$ make altinstall
$ vim helloworld.py
# helloworld program
print('Hello world')

press “esc” and type 😡 (save and exit)

now execute the python code

$ python helloworld.py

Sort Array object python

This code will help to sort any custom list object in ascending or descending order

accuracy=[
        {
            "Alg": "DecisionTree",
            "val": 90
        },
        {
            "Alg": "GradientBoosting",
            "val": 60
        },
        {
            "Alg": "LinearRegression",
            "val": 95
        },
        {
            "Alg": "LogisticRegression",
            "val": 96
        }
    ]

ascending=sorted(accuracy, key = lambda i: float(i['val']))
print(ascending)
desc=sorted(accuracy, key = lambda i: float(i['val']),reverse=True)
print(desc)
Output

[{'Alg': 'GradientBoosting', 'val': 60}, {'Alg': 'DecisionTree', 'val': 90}, {'Alg': 'LinearRegression', 'val': 95}, {'Alg': 'LogisticRegression', 'val': 96}]
[{'Alg': 'LogisticRegression', 'val': 96}, {'Alg': 'LinearRegression', 'val': 95}, {'Alg': 'DecisionTree', 'val': 90}, {'Alg': 'GradientBoosting', 'val': 60}]

Read Excel file using Python

This article shows how to import data from Excel using Python.

Step 1: install pandas

open Ananconda Command Prompt

Step 2: install pandas

\> pip install pandas

Read excel file

import pandas as pd
dataset1=pd.read_excel("C:/folderpath/filname.xlsx",sheet_name="sheetname")
dataset1.head()
print(dataset1.get("columnname"))

Read data from CSV File

import pandas as pd
dataset1=pd.read_csv("C:/foldername/filename.csv",encoding='ISO-8859-1')
dataset1.head()
print(dataset1.get("columnname"))