Maryam Anwer
Maryam Anwer

Reputation: 43

issue in python and sql query

I have three datasets in csv files.
One csv contains type which is small_ airport, Large_airport and medium_airport. other csv contains id, airport_ref, airport_ident, type, description, frequency_mhz. Now I am doing join each category, large_airport, medium_airport, small airport to the communication frequencies ‘frequency_mhz’. the code is

ps.sqldf('select airport_ident, airport_freq.type, description, frequency_mhz from airport_freq\
         join airports on airport_freq.airport_ref = airports.id where airports.type = "large_airport"')

Similar to what I did for small and medium airport, now I want to produce the mean, mode and median for the ‘frequency_mhz’ for each large_airport and frequencies more than 100 mhz. I used:

ps.sqldf('select max(frequency_mhz), min(frequency_mhz), avg(frequency_mhz) from airport-frequencies').

It gives an error:

PandaSQLException: (sqlite3.OperationalError) near "-": syntax error
[SQL: select max(frequency_mhz), min(frequency_mhz), avg(frequency_mhz) from airport-frequencies]
(Background on this error at: http://sqlalche.me/e/e3q8)

how can I calculate the mean, mode and median for the ‘frequency_mhz’ For each large_airport and frequencies more than 100 mhz?

Upvotes: 0

Views: 96

Answers (2)

prateek bandi
prateek bandi

Reputation: 51

Please rename 'airport-frequencies' to 'airport_frequencies', your query will work fine. SQL does not deal very well with "-", so avoid using it.

Upvotes: 1

hYg-Cain
hYg-Cain

Reputation: 408

ps.sqldf("select max(frequency_mhz), min(frequency_mhz), avg(frequency_mhz) from 'airport-frequencies'").

I guess this table does not exist, did you mean airport_freq? Or if it does you have to handle the "-"

Upvotes: 0

Related Questions