1

I have found this python model online which has example and I'm trying to use example but it's not working. Example and other related things can be found here: https://github.com/USEPA/IO-Model-Builder/blob/master/example/example.ipynb

I tried to run provided example line by line in Jupyter Notebook, but I got stuck when I got to Satellite tables.

When I run this chunk of code:

sat_i = iomb.make_sat_table('satellite_table.csv')
sat_c = sat_i.apply_market_shares(io_model.get_market_shares(), 'sector_meta_data.csv')
sat_c.to_csv('satellite_table_com.csv')

I got this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_13756\2825653640.py in ?()
      1 sat_i = iomb.make_sat_table('satellite_table.csv')
----> 2 sat_c = sat_i.apply_market_shares(io_model.get_market_shares(), 'sector_meta_data.csv')
      3 
      4 #sat_c.to_csv('satellite_table_com.csv')

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\iomb\sat.py in ?(self, market_shares sector_info_csv)
    313             new_table.sectors.append(new_sector)
    314             new_table.sector_idx[new_sector.key] = new_col
    315             share_entries = {}
    316             shares[new_col] = share_entries
--> 317             m_shares = market_shares.ix[:, commodity]
    318             for industry_key in m_shares.index:
    319                 share = m_shares[industry_key]
    320                 if share == 0:

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py in ?(self, name)
   5985             and name not in self._accessors
   5986             and self._info_axis._can_hold_identifiers_and_holds_name(name)
   5987         ):
   5988             return self[name]
-> 5989         return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'ix'

It refers to the model, I cannot understand why this doesn't work. Any ideas what I could do to make it word?

Thanks in advance!

fox23441
  • 11
  • 2
  • No, I tried to replicate model and change it from 'm_shares = market_shares.ix[:, commodity]' to 'm_shares = market_shares.loc[:, commodity]' but I got the same error – fox23441 Sep 01 '23 at 14:01

1 Answers1

0
--> 317             m_shares = market_shares.ix[:, commodity]
    ...
AttributeError: 'DataFrame' object has no attribute 'ix'

You are spelunking through some ancient code, authored in September 2016. That falls between this pair of pandas releases:

  • 0.18.1 in May 2016
  • 0.19.0 in October 2016

Please refer to this bit of official documentation:

IX indexer is deprecated

Warning

Starting in 0.20.0, the .ix indexer is deprecated, in favor of the more strict .iloc and .loc indexers.

In your current environment, attempting to access .ix won't work. That method has been removed from 2.1.0 and other modern pandas releases.

You can set the controls of the way-back machine to use library dep versions similar to what the original author tested against. Or you can choose to port this code so it conforms to modern conventions, by following the doc's helpful advice.

J_H
  • 17,926
  • 4
  • 24
  • 44