Informatics Practices
The python code written below has syntactical errors. Rewrite the correct code and underline the corrections made.
Import pandas as pd
df = {"Technology" : ["Programming", "Robotics", "3D Printing"],
"Time(in months)" : [4, 4, 3]}
df = Pd.dataframe(df)
Print(df)
Python Pandas
1 Like
Answer
Import pandas as pd #Error 1
df = {"Technology" : ["Programming", "Robotics", "3D Printing"],
"Time(in months)" : [4, 4, 3]}
df = Pd.dataframe(df) #Error 2
Print(df) #Error 3
Error 1 — The 'i' in import statement should be in lowercase as it's a reserved keyword in Python.
Error 2 — Alias pd for pandas library should be same as defined with lowercase 'p' and the DataFrame constructor should have a capital 'D' and capital 'F'.
Error 3 — The print function should be written with 'p' in lowercase, as it's a built-in Python function.
The corrected code is :
import pandas as pd
df = {"Technology" : ["Programming", "Robotics", "3D Printing"],
"Time(in months)" : [4, 4, 3]}
df = pd.DataFrame(df)
print(df)
Answered By
2 Likes
Related Questions
Briefly explain the basic concepts of a web server and web hosting.
Rati is doing a course in networking. She is unable to understand the concept of URL. Help her by explaining it with the help of suitable example.
Consider the given SQL string :
"12#All the Best!"Write suitable SQL queries for the following :
(i) Returns the position of the first occurrence of the substring "the" in the given string.
(ii) To extract last five characters from the string.
Predict the output of the given Python code :
import pandas as pd list1 = [-10, -20, -30] ser = pd.Series(list1 * 2) print(ser)