0

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?

2
  • "its give error": please edit your question to include the error that you get. Commented Apr 17, 2022 at 19:07
  • i edit the question Commented Apr 17, 2022 at 20:52

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

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

5 Comments

the table is available when i see, pd.read_csv('../input/airports-data/from airport-frequencies.csv') and these are column name ( id airport_ref airport_ident type description frequency_mhz)
then try adding quotes --> from "airport-frequencies"
its give SyntaxError: EOL while scanning string literal. Other than SQL query, what technique can i use to get mean, medium and mode?
since you're already in quotes you'd have to espace them, or try as edited in my given answer.
In regards of other solutions: You could select all required values and calculate the max, min, avg in python, but since there is the option to do it when retrieving the data you should use that option since it is better from performance and readability point of view. Also you should try and avoid names that require escaping like " - " does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.