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

1 Like


Related Questions