Data Analytics with Python by Frank Millstein
Author:Frank Millstein
Language: eng
Format: epub
Tags: Data analytics applications, Data analytics process, Data Analytics With Python, Data Analytics, Python, Python data structures, Python libraries, Data exploration using Pandas, Pandas series, Data munging, Data manipulation
Publisher: Frank Millstein
Published: 2019-10-18T00:00:00+00:00
CARRYING OUT BINARY OPERATIONS
Dataframe has the methods sub, add, mul and div and all related functions including rsub, radd and others for carrying different binary operations. For broadcasting behavior, the series input is of primary interest. Using these listed functions, you can easily match on columns or on the index using the axis keyword as illustrated below.
df = pd . DataFrame ( {' one ' : pd . Series ( np . random . randn ( 3 ), index = [' a ', ' b ', ' c ' ] ),
....: ' two ' : pd.Series ( np . random . randn (4), index = [ ' a ', ' b ', ' c ', ' d ' ] ),
....: ' three ' : pd . Series ( np . random . randn ( 3 ), index = [ ' b ', ' c ', ' d ' ] ) } )
....:
df
Output:
one three two
a - 1.101558 NaN 1.124472
b - 0.177289 - 0.634293 2.487104
c 0.462215 1.931194 - 0.486066
d NaN - 1.222918 - 0.456288
row = df . iloc [ 1 ]
column = df [ ' two ' ]
df . sub ( row , axis = ' columns ' )
Output:
one three two
a - 0.924269 NaN - 1.362632
b 0.000000 0.000000 0.000000
c 0.639504 2.565487 - 2.973170
d NaN - 0.588625 - 2.943392
df . sub ( row, axis = 1 )
Output :
one three two
a - 0.924269 NaN - 1.362632
b 0.000000 0.000000 0.000000
c 0.639504 2.565487 - 2.973170
d NaN - 0.588625 - 2.943392
df . sub ( column, axis = ' index ' )
Output :
one three two
a - 2.226031 NaN 0.0
b - 2.664393 - 3.121397 0.0
c 0.948280 2.417260 0.0
d NaN - 0.766631 0.0
df . sub ( column , axis = 0 )
Output :
one three two
a - 2.226031 NaN 0.0
b - 2.664393 - 3.121397 0.0
c 0.948280 2.417260 0.0
d NaN - 0.766631 0.0
You also can align a level of your multi-indexed dataframe with series as follows.
dfmi = df . copy ( )
dfmi . index = pd . MultiIndex . from _ tuples( [ ( 1,' a ' ),( 1,' b ' ),( 1,' c ' ),( 2,' a ' ) ],
....: names = [ ' first ' , ' second ' ] )
....:
dfmi . sub ( column , axis = 0, level = ' second ' )
Output :
one three two
first second
1 a - 2.226031 NaN 0.00000
b - 2.664393 - 3.121397 0.00000
c 0.948280 2.417260 0.00000
2 a NaN - 2.347391 -1.58076
In dataframe and series, the arithmetic functions have the option of inputting a fill value that has a value to substitute when some of the values at a location are missing. For instance, when you add two dataframe objects, you may want to treat NaN as zero unless both of your dataframes are missing that value. In this case, the result you get is NaN and later you can replace NaN with another value using this fill value argument if your want.
df
Output :
one three two
a - 1.101558 NaN 1.124472
b - 0.177289 - 0.634293 2.487104
c 0.462215 1.931194 - 0.486066
d NaN - 1.222918 - 0.456288
df2
Output :
one three two
a - 1.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9912)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9795)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8293)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7775)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7758)
Grails in Action by Glen Smith Peter Ledbrook(7693)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Windows APT Warfare by Sheng-Hao Ma(6804)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6528)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6396)
Kotlin in Action by Dmitry Jemerov(5062)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Functional Programming in JavaScript by Mantyla Dan(4037)
Solidity Programming Essentials by Ritesh Modi(3985)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3773)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3716)
The Ultimate iOS Interview Playbook by Avi Tsadok(3692)
