Introductie tot DataFrames

Python voor MATLAB-gebruikers

Justin Kiggins

Product Manager

DataFrames

  • pandas-pakket
  • Tabeldata
  • pandas DataFrame = MATLAB-tabel
  • Sla data op met gemengde types per observatie:
    • floats
    • integers
    • booleans
    • strings
Python voor MATLAB-gebruikers

DataFrames

                     rank num_households frac_dog_owners frac_cat_owners
state
Alabama              17   1828000        0.441           0.274          
Arizona              18   2515000        0.401           0.296          
Arkansas             6    1148000        0.479           0.306          
California           40   12974000       0.328           0.283          
Colorado             13   1986000        0.425           0.323          
Connecticut          33   1337000        0.283           0.319          
Delaware             25   334000         0.337           0.337          
District of Columbia 48   287000         0.131           0.116          
Florida              32   7609000        0.357           0.273          
Georgia              31   3798000        0.401           0.273
Python voor MATLAB-gebruikers

Methode .head()

pets.head()
            rank  num_households  frac_dog_owners  frac_cat_owners
state                                                             
Alabama       17         1828000            0.441            0.274
Arizona       18         2515000            0.401            0.296
Arkansas       6         1148000            0.479            0.306
California    40        12974000            0.328            0.283
Colorado      13         1986000            0.425            0.323
Python voor MATLAB-gebruikers

Attribuut .columns

pets.columns
Index(['rank', 'num_households', 'frac_dog_owners', 'frac_cat_owners'],
      dtype='object')
Python voor MATLAB-gebruikers

Attribuut .index

pets.index
Index(['Alabama', 'Arizona', 'Arkansas', 'California', 'Colorado',
       'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 
       'Georgia', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 
       'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 
       'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 
       'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico',
       'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 
       'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 
       'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia',
       'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'],
      dtype='object', name='state')
Python voor MATLAB-gebruikers

Eén kolom ophalen

pets['rank']
state
Alabama                 17
Arizona                 18
Arkansas                 6
California              40
...
Virginia                37
Washington               5
West Virginia            7
Wisconsin               21
Wyoming                  9
Name: rank, dtype: int64
Python voor MATLAB-gebruikers

Compatibel met NumPy & Matplotlib

plt.scatter(pets['frac_dog_owners'], pets['frac_cat_owners'])

spreidingsdiagram van katten en honden

Python voor MATLAB-gebruikers

Laten we oefenen!

Python voor MATLAB-gebruikers

Preparing Video For Download...