Skip to content

Instantly share code, notes, and snippets.

View aveek22's full-sized avatar
🏠
Working from home

Aveek aveek22

🏠
Working from home
View GitHub Profile
select * from cs621labexam1;
--1
select * from cs621labexam1 where char_length(observer) > 9;
--2
select * from cs621labexam1
where 1=1
and date_part('month', ts) = 01
and date_part('year', ts) = 2019
@aveek22
aveek22 / export_data_from_pandas.py
Created December 25, 2020 10:11
This file exports data from pandas to a table in PostgreSQL database.
import pandas as pd
import sqlalchemy
# Create the engine to connect to a PostgreSQL database
engine = sqlalchemy.create_engine('postgresql://aveek:test1234@localhost:5432/sql-shack-demo')
# Read data from the SQL Table
data = pd.read_csv('superstore.csv')
# Print first few rows of the dataframe
from flask import Flask
from flask_restful import Api, Resource, reqparse
import pandas as pd
app = Flask(__name__)
api = Api(app)
class Users(Resource):
def get(self):
data = pd.read_csv('users.csv')
class Users(Resource):
def get(self):
data = pd.read_csv('users.csv')
data = data.to_dict('records')
return {'data' : data}, 200
def post(self):
parser = reqparse.RequestParser()
parser.add_argument('name', required=True)
if __name__ == '__main__':
app.run()
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 4 columns, instead of 5. in line 4.
order,product,qty,amount
1,car,2,5000
2,bikes,1,2000
3,cookies,10,80
4,phone,1,5,300
# imports the JSON library to work in python
import json
# assign the JSON data to a variable
json_data = """{
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
# imports the Pandas library to work in python
import pandas as pd
# assign the JSON data to a variable
json_data = """{
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
# imports the Pandas library to work in python
import pandas as pd
# Create the data as a list
data = [['Bob', 30], ['Fred', 35], ['Nick', 40]]
# Load the data as a dataframe
df = pd.DataFrame(data=data, columns=['Name','Age'])
# Covnert the dataframe to JSON
import json
def greet():
print('Hello user')
def main():
greet()
if __name__ == '__main__':
main()