- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Pandas is built on top of NumPy, which means the Python pandas package depends on the NumPy package and also pandas intended with many other 3rd party libraries. So we can say that Numpy is required for operating the Pandas.

The pandas library depends heavily on the Numpy array for the implementation of pandas data objects.

import pandas as pd df = pd.DataFrame({'A':[1,2,3,4], 'B':[5,6,7,8]}) print('Type of DataFrame: ',type(df)) print('Type of single Column A: ',type(df['A'])) print('Type of values in column A',type(df['A'].values)) print(df['A'].values)

df variable stores a DataFrame object created by using python dictionary, this DataFrame having 2 columns named as A and B. In the third of the above code, we are trying to display the type of our dataFrame it will display pandas core Dataframe. The fourth line will print the type of single column which is A the resultant output will be pandas Series. The fifth line is going to display the type of values available in that single column A.

Type of DataFrame: <class 'pandas.core.frame.DataFrame'> Type of single Column A: <class 'pandas.core.series.Series'> Type of values in column A <class 'numpy.ndarray'> array([1, 2, 3, 4], dtype=int64)

The third line of the output displays that data is representing the Numpy array object in our above pandas example. In our example, we are not even imported the NumPy package.

import pandas as pd df = pd.DataFrame([['a','b'],['c','d'],['e','f'],['g','h']], columns=['col1','col2']) print('Type of DataFrame: ',type(df)) print('Type of single Column A: ',type(df['col1'])) print('Type of values in column A',type(df['col1'].values)) print(df['col1'].values)

In the following example, we have a DataFrame df created by using python lists of lists. This DataFrame df has 2 columns named col1 and col2. We try to print the type of single column “col1” and the resultant output will be pandas Series. If we print the type of values available in that column col1 we can see that the output will be numpy.ndarray.

Type of DataFrame: <class 'pandas.core.frame.DataFrame'> Type of single Column A: <class 'pandas.core.series.Series'> Type of values in column A <class 'numpy.ndarray'> ['a' 'c' 'e' 'g']

Now we can say that the pandas columns can be built on the basics of the NumPy array object. You don’t need to import it specifically when working with Pandas. And when you install Pandas you can see that your package manager will automatically install the Numpy package if you have not installed NumPy before.

- Related Questions & Answers
- How does the precedence of || operator depend on PIPES_AS_CONCAT SQL mode?
- How does the portfolio risk depend on the correlation between assets?
- How does running a specific test method depend on another test method in TestNG?
- How does the execution of a particular test method depend on other test methods in TestNG?
- Python - Filter Pandas DataFrame with numpy
- Which is faster, NumPy or pandas?
- Convert a Pandas DataFrame to a NumPy array
- Python - Count distinct in Pandas Aggregation with Numpy
- What is the difference between NumPy and pandas?
- Python Pandas and Numpy - Concatenate multiindex into single index
- Python Pandas - Convert the Timedelta to a NumPy timedelta64
- Python Pandas - Return numpy array of python datetime.date objects
- Python Pandas - Return numpy array of python datetime.time objects
- PHP_CodeSniffer, PHPMD or PHP Depend
- Add a temporary column in MySQL where the values depend on another column?

Advertisements