0

I need to get this result for an assignment using python/sqlite3. required result

I did my query in MYSQL, and I got the answer already to the assignment question. Since I am learning, I find it easier to do the queries using MySQL Workbench first. result in MySQLWorkbench

However, When I try to do it in Jupyter notebook with Sqlite3, it only shows the zeros on the percentage column. I am using the function pd.read_sql_query. I went to the documentation and could not find any arguments there that would do what I want, or I did not understand it. I played with the coarse_float argument, but it did not make a difference. I am learning, so sometimes, I do not understand the documentation completely.

query_results = pd.read_sql_query(query1,conn)

This is what I get in my Jupyter notebook: Output un Jupyter Notebook

I know the numbers are there because if I multiple the column ”percentage_female_only_movie” fly 100, I see them. I would like to know how to show them like in MYSQLWorkbench.

Thank you for any help. An if you know any link where I can learn about this type of issues, I would love if you can share it.

2 Answers 2

1

Try df[colname] = df[colname].astype(float).

This would convert your column to float and you should see the values

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

1 Comment

I tried it before and it did not work. ""q11b_results = pd.read_sql_query(q11b,conn) q11b_results["Percentage_Female_only_Movie"].astype(float)""". I also tried """pd.options.display.float_format = "{:,.4}".format""", but it did not work either
0

I found the solution. I needed to CAST the numerator and denominator of the column I was generating in SELECT statement of my query.

SELECT SUBSTR(TRIM(m.year),-4) AS Movie_year,
    ROUND(CAST(fcm.Female_Cast_Only_Movies*100 AS FLOAT)/ CAST(tm.movies_total AS FLOAT),2) AS Percentage_Female_only_Movie,
   tm.movies_total As Total_movies

FROM Movie AS m

output:

enter image description here

Comments

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.