Top 5 Built-In Python Functions For Data Science
source link: https://www.journaldev.com/61878/top-built-in-python-functions-for-data-science
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Top 5 Built-In Python Functions For Data Science
Most Data Scientists and Analysts use Python and R programming. But, Python, with its flexibility, Simplicity, and Availability of awesome libraries, it’s a go-to language for Data Science. From Analysis to Visualization and Modelling to Deployment, Python libraries play a huge role. Libraries like Pandas, Numpy, and Scikit Learn boost python’s capability to work with advanced problems. But, in between all these, Python offers some advanced built-in functions which will help you a lot. In this article, let’s see our top 10 built-in functions in Python for Data Science.
Top Built-in Python Functions for Data Science
1. Python Filter
The filter function is a python’s built-in function that you can use to iterate over the elements. It will return the items as per the defined condition.
Let’s see how it works.
#Filter my_list = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] def even(number): return number % 2 = = 0 output = filter (even, my_list) print ( list (output)) |
Output –
[2, 4, 6, 8, 10, 12]
- The filter function will return the elements which satisfies our condition.
2. Python Map
Python Map() function will take another function and an iterable object. It will return the elements which satisfy the given condition.
The best thing about the map function is, it can be used without Loops.
#map num = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] def doubler(number): return number * 2 output = map (doubler, num) print ( list (output)) |
Output –
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
- This method is widely known as Mapping.
3. InsInstance
Isinsatnce()
is a built-in python function that you can use to check if an element belongs to a specific class or not.
This function will return a Boolean output.
#Ininstance a = [ 'Jay' , 'Eva' , 'Nathaniel' , 'Elisha' ] b = ( 'a' , 'b' , 'c' , 'd' , 'e' ) c = [ 1 , 2 , 3 , 4 , 5 ] print ( isinstance (a, list )) print ( isinstance (b, tuple )) print ( isinstance (c, dict )) |
Output –
True True False
- This function will return if the object belongs to particular class or not.
4. Python Round
The Python round() function is used to round off the decimal numbers. It will be of great use when you working with data manipulation and calculations.
Let’s see how it works.
#Round #round with decimal points num = 45.678100 print ( round (num)) #round with 2 decimal points num = 45.678100 print ( round (num, 2 )) #universal example pi = 3.14159265359 print ( round (pi, 2 )) |
- When you are working with numerical data, the Round function will provide much-needed assistance.
5. Python Zip
Python zip() is another python built-in function that can be used to assign different elements from different iterators.
This function will provide output which includes a tuple. Let’s see how it works.
#Zip #Lists first = [ 'Megan' , 'Geremy' , 'Riya' ] second = [ 'Rage' , 'Holder' , 'Bansal' ] #Zip function output = zip (first,second) #Ouput print ( list (output)) |
Output –
[('Megan', 'Rage'), ('Geremy', 'Holder'), ('Riya', 'Bansal')]
- Zip returns the tuple based list as shown above.
Built-in Python Functions – Conclusion
There are many built-in python functions that allow us to perform simple to advanced tasks with less code. Here, I have shown the top 5 built-in python functions for your data science tasks. That’s all for now. Happy Python!!!
More read – Python functions
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK