I am trying to create few tables in Postgres from pandas dataframe but I am kept getting this error. psycopg2.errors.InvalidForeignKey: there is no unique constraint matching given keys for …
Tag: pandas
IBM DB2 CAST AS VARCHAR versus Python Pandas to_datetime Function
I have the line in a SQL file hitting an IBM DB2 database. For various reasons, I have to convert to VARCHAR, so leaving out the CAST is not an option. The problem is that this casting is choosing a very poor format. The result comes out like this: 2020-06-09-13.15.00.000000. We have the four-digit year with century, month, day of
SQL apply where clause to an arbitrary query results
I’m working on a system where the user introduces an SQL server/db connection and a valid SQL query, which I save on my system. I’m using python+sqlalchemy+pandas to accomplish this. That query will return a table like this one, in which the only rule is that the query result must have a timestamp as DateTime field and at least another
Python/Excel/SQL column dates to exploded rows
I have an Excel spreadsheet table like this where it shows how many units were sold each week for 2019 and 2020 (columns) and I am trying to put it into an access database formatted like the second …
SQL – Conditionally join and replace values between two tables
I have two tables where one is holding “raw” data and another is holding “updated” data. The updated data just contains corrections of rows from the first table, but is essentially the same. It is a functional requirement for this data to be stored separately. I want a query with the following conditions: Select all rows from the first table
psycopg2: cursor.execute storing only table structure, no data
I am trying to store some tables I create in my code in an RDS instance using psycopg2. The script runs without issue and I can see the table being stored correctly in the DB. However, if I try to retrieve the query, I only see the columns, but no data: This script runs without issues and, printing out file_check
Pandas equivalent for SQL – arithmetic expression within aggregate function
I am a pandas newbie coming from a SQL background although have some exposure to Python. I was wondering if there is a simple way to do the following SQL code in pandas dataframe: Below is all I got so far there doesn’t seem to be a syntax to include arithmetic expressions: Thanks in advance. Answer try this,
How do I extract these SQL queries from these pandas dataframes?
SQL QUERIES Using SQL or Pandas, please tell me how to 1. Compare the monthly sales (GMV) trend in Q4 2019, across all countries (venture_code) 2. Show the top 10 brands for each product category, based on total sales (GMV) I wrote but got the query wrong! Answer Concerning the error, you have a space in the column name. In
doing some of columns based on some complex logic in pyspark
Here is the question in the image attached: Table: So result column is calculated based on the below rules: If col3 >0 , then result=col1+col2 If col 3=0, then result= sum (col2) till col3 >0 + col1(where col3>0) for example for row =3, the result=60+70+80+30(from col1 from row 5 because here col3>0)=240 for row=4, the result=70+80+30(from col1 from row 5
How to get column names from a SQL query?
I need to put data from the SQL query into a Pandas dataframe. Please tell me is it possible to get column names the query results? I found that there is a keys() function in sqlalchemy for that but it does not work for me: AttributeError: ‘CMySQLCursor’ object has no attribute ‘keys’ Answer I think that it your are searching