- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to import Pandas package?
Pandas is a python package that has a set of tools (nothing but functions) that can deal with data. By using this set of tools we can perform required tasks on our data.
To get all these tools into our python workspace we need to import the package first. To do this importing process we have to use the python import keyword.
By default, Python doesn’t load all of the libraries available to it. Due to this, we need to add an import statement to our code to utilize the library tools (functions).
The syntax of importing a library is the import keyword followed by the library name. Let’s see in the below block of code for an example.
Example
import pandas
Output
Using the above line of code we can get all features available in the pandas package, and that can be used further. The result of this line of code won’t return any output. We will get an error message like ‘ModuleNotFoundError’ if you give the wrong name of our package.
To use a function or a tool that is available in our package we need to use the package name and function name for each time. Let’s see the syntax below.
Example
pandas.get_dummies()
Explanation
By adding the library name with a . before the function name tells Python where to find the function. Here get_dummies is a pandas function to convert categorical data into dummy variables.
If you want to change the library name to a shortened name like a nickname. We can add as
If we want to give the library a nickname to shorten the command, which can be called an alias. This can be done by using an as keyword in python. Let’s see an example by adding a common nickname to our pandas library below.
Example
Import pandas as pd pd.read_csv()
Explanation
In the example above, we have imported Pandas as pd. This means we don’t have to type out pandas each time to call any Pandas function. Here pd is pandas nickname and read_csv() is the pandas method that will read a file with the .csv extension.
- Related Articles
- How to import everything from a python namespace / package?
- How to import classes from within another directory/package in Java?
- Difference between import and package in Java?
- How to install pandas using the python package manager?
- Can I import same package twice? Will JVM load the package twice at runtime?
- How do I import all the submodules of a Python namespace package?
- Is there a need to import Java.lang package while running Java programs?
- Do I need to import the Java.lang package anytime during running a program?
- Can we define a package after the import statement in Java?
- Why we do not import a package while we use any string function?
- How to access Java package from another package
- What are the data structures in the Python pandas package?
- How to import other Python files?
- How to import Matplotlib in Python?
- How to Import Collection in Postman?
