Python for Business Analyst

Python Example – Write a Python program to make file lists from current directory using a wildcard

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to make file lists from current directory using a wildcard.   Sample Solution Python Code: import glob file_list = glob.glob(‘*.*’) print(file_list) Sample Output: [’30eb5e10-2675-11e7-a9c1-cf681af3cdf1.py’, ‘test.txt’, ‘abc.py’, ‘ mynewtest.txt’, ‘myfile.txt’, ‘logging_example.out’, ’35ba4b40-2675 -11e7-a9c1-cf681af3cdf1.py’, ’30c8bae0-2675-11e7-a9c1-cf681af3cdf1. py’, ‘abc.txt’, ‘exercise.cs’, ‘Example.cs’, ‘myfig.png’, ‘file.out ‘, ‘line.gif’, …

Python Example – Write a Python program to get numbers divisible by fifteen from a list

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get numbers divisible by fifteen from a list.   Sample Solution Python Code: num_list = [45, 55, 60, 37, 100, 105, 220] result = list(filter(lambda x: (x % 15 == 0), num_list)) print(“Numbers divisible by 15 are”,result) Sample Output: Numbers …

Python Example – Write a Python program to check if a number is positive, negative or zero

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check if a number is positive, negative or zero.   Sample Solution Python Code: num = float(input(“Input a number: “)) if num > 0: print(“It is positive number”) elif num == 0: print(“It is Zero”) else: print(“It is a negative …

Python Example – Write a Python program to retrieve file properties

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to retrieve file properties.   Sample Solution Python Code: import os.path import time print(‘File :’, __file__) print(‘Access time :’, time.ctime(os.path.getatime(__file__))) print(‘Modified time:’, time.ctime(os.path.getmtime(__file__))) print(‘Change time :’, time.ctime(os.path.getctime(__file__))) print(‘Size :’, os.path.getsize(__file__)) Sample Output: File : 8dbacd90-266d-11e7-a9c1-cf681af3cdf1.py Access time : Fri Apr 21 …

Python Example – Write a Python program to get the users environment

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the users environment.   Sample Solution Python Code: import os print() print(os.environ) print() Sample Output: environ({‘SHLVL’: ‘3’, ‘COMP_WORDBREAKS’: ‘ \t\n”\’><;|&(:’, ‘LESSC LOSE’: ‘/usr/bin/lesspipe %s %s’, ‘TERM’: ‘xterm’, ‘LS_COLORS’: ‘rs =0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:c d=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow =34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj= 01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31: *.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01; 31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01; 31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz= 01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:* .sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=0 1;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.g …

Python Example – Write a Python program to extract the filename from a given path

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to extract the filename from a given path.   Sample Solution Python Code: import os print() print(os.path.basename(‘/users/system1/student1/homework-1.py’)) print() Sample Output: homework-1.py   Write a Python program to extract the filename from a given path Free Machine Learning & Data Science Coding …

Python Example – Write a Python program to get the name of the host on which the routine is running

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the name of the host on which the routine is running.   Sample Solution Python Code: import socket host_name = socket.gethostname() print() print(“Host name:”, host_name) print() Sample Output: Host name: server   Write a Python program to get the …

Python Example – Write a Python program to get the system time

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to get the system time. Note : The system time is important for debugging, network information, random number seeds, or something as simple as program performance.   Sample Solution: Python Code: import time print() print(time.ctime()) print() Sample Output: Thu Apr 29 …

Python Example – Write a Python program to list the special variables used within the language

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to list the special variables used within the language.   Sample Solution Python Code: s_var_names = sorted((set(globals().keys()) | set(__builtins__.__dict__.keys())) – set(‘_ names i’.split())) print() print( ‘\n’.join(‘ ‘.join(s_var_names[i:i+8]) for i in range(0, len(s_var_names), 8)) ) print() Sample Output: ArithmeticError AssertionError AttributeError BaseException …

Python Example – Write a Python program to check whether a string is numeric

(Python Example for Citizen Data Scientist & Business Analyst)   Write a Python program to check whether a string is numeric.   Sample Solution Python Code: str = ‘a123’ #str = ‘123’ try: i = float(str) except (ValueError, TypeError): print(‘\nNot numeric’) print() Sample Output: Not numeric   Write a Python program to check whether a …