yhat / pandasql

sqldf for pandas
MIT License
1.33k stars 185 forks source link

SELECT * returns a dataframe with an explicit Index column? #28

Closed psychemedia closed 10 years ago

psychemedia commented 10 years ago

If I try to select all columns from a dataframe with SELECT *, the dataframe I get in return includes a new, explicitly labelled, index column?

glamp commented 10 years ago

do you have some examples?

psychemedia commented 10 years ago

How about this?

import pandas as pd
#Set up a dummy dataframe
courseData= { 'courseCode': ['TM351','TU100','M269'],
              'points':[30,60,30],
              'level':['3','1','2']
             }
course_df=pd.DataFrame( courseData )

from pandasql import sqldf
pysqldf = lambda q: sqldf(q, globals())

q='''
    SELECT * FROM course_df;
  '''
pysqldf(q)

which returns:

    index   courseCode  level   points
0    0   TM351   3   30
1    1   TU100   1   60
2    2   M269    2   30
glamp commented 10 years ago

fixed in 42949a9ce7e0b384b1fd9b146e78ae70841a5986