11.0.4 Use SQL to perform a Group By operation
Example:
import pandasql as pql import pandas as pd
# Create an example dataset
DF = pd.DataFrame()
DF['A'] = ['a','b', 'c','a','b', 'c','a','b', 'c']
DF['B'] = [ 1 , 2 , 5 , 2 , 4 , 7 , 8 , 3 , 6 ]
# Write a SQL query and save it as a string
# Refer to your DFs in your SQL as though they were tables
sql = '''SELECT A
, Sum(B) AS Sum_B
FROM DF
Group by A
'''
# run your query and save the resulting DF to use as you see fit
New_DF = pql.sqldf(sql, locals())