Home > Enterprise >  issue in python and sql query
issue in python and sql query

Time:04-18

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?

CodePudding user response:

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 "-"

CodePudding user response:

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

  • Related