Skip to main content

Posts

Showing posts from February, 2023

Json to excel in Python and Read Json file content in Python

  Below is the program to convert JSON file content into excel in Python. For this, you need to import json import json import csv import pandas as pd from payLoad import * json_file = {     "key1":"Value1",     "key2":"Value2",     "key3":"Value3", } pd.DataFrame(json_file).to_excel("excel.xlsx") ===================================================================== Below is the program to Read Json file content in Python For this, you need to import JSON import json with open('C:\\Users\\my_json_test_file.json') as f:     data = json.load(f) print(data)

How to connect to a remote database in Python

 Following is the program which will guide you on how to connect to a remote database in Python. For this first, you need to install the database connector and then use the following code.  You can install the connector with the following command: $> pip install <your database connector MySQL/memsql> import mysql.connector from mysql.connector import Error try:     connection = mysql.connector.connect(host='<provide remote hostname here>',                                          database='<provide database name here>',                                          user='<userid>',                                          password='<...

Python programs for printing patterns

  Here are some examples of Python programs for printing patterns: To print a triangle pattern: def triangle(n):     for i in range(1, n+1):         print(" "*(n-i) + "*"*(2*i-1)) triangle(5) Output: * *** ***** ******* ********* ============================================================ To print a pyramid pattern: def pyramid(n): for i in range(1, n+1): print(" "*(n-i) + "*"*(2*i-1)) pyramid(5) Output: * *** ***** ******* ********* ******* ***** *** * ============================================================ To print a diamond pattern: def diamond(n): for i in range(1, n+1): print(" "*(n-i) + "*"*(2*i-1)) for i in range(n-1, 0, -1): print(" "*(n-i) + "*"*(2*i-1)) diamond(5)     *    ***   *****  ******* *********  *******   *****    ***     *