Learn the "02-orbit-determination-example.ipynb" problam in Jupyter Lab

Hello, everyone. I’m a new in Orekit. Now I’m learning the problem “02-orbit-determination-example.ipynb” , but I met some problems need your help.

When I run the following code ,
stationFile = ‘SLRF2014_POS+VEL_2030.0_180504.snx’
stationEccFile = ‘ecc_xyz.snx’
import slrDataUtils
stationData = slrDataUtils.parseStationData(stationFile, stationEccFile, startCollectionDate)

It appeared the following error,

KeyError Traceback (most recent call last)
File D:\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3621, in Index.get_loc(self, key, method, tolerance)
3620 try:
→ 3621 return self._engine.get_loc(casted_key)
3622 except KeyError as err:

File D:\anaconda3\lib\site-packages\pandas_libs\index.pyx:136, in pandas._libs.index.IndexEngine.get_loc()

File D:\anaconda3\lib\site-packages\pandas_libs\index.pyx:163, in pandas._libs.index.IndexEngine.get_loc()

File pandas_libs\hashtable_class_helper.pxi:2131, in pandas._libs.hashtable.Int64HashTable.get_item()

File pandas_libs\hashtable_class_helper.pxi:2140, in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 0

The above exception was the direct cause of the following exception:

KeyError Traceback (most recent call last)
Input In [19], in <cell line: 4>()
2 stationEccFile = ‘ecc_xyz.snx’
3 import slrDataUtils
----> 4 stationData = slrDataUtils.parseStationData(stationFile, stationEccFile, startCollectionDate)
5 display(stationData)

File G:\py\laser-orbit-determination-master\slrDataUtils.py:143, in parseStationData(stationFile, stationEccFile, epoch)
141 for stationId, staData in stationData.iterrows():
142 indexTuple = (staData[‘CODE’], staData[‘PT’])
→ 143 refEpoch = stationxyz.loc[indexTuple, ‘REF_EPOCH’][0]
144 yearsSinceEpoch = (epoch - refEpoch).days / 365.25
146 pv = pivotTable.loc[indexTuple][‘ESTIMATED_VALUE’]

File D:\anaconda3\lib\site-packages\pandas\core\series.py:958, in Series.getitem(self, key)
955 return self._values[key]
957 elif key_is_scalar:
→ 958 return self._get_value(key)
960 if is_hashable(key):
961 # Otherwise index.get_value will raise InvalidIndexError
962 try:
963 # For labels that don’t resolve as scalars like tuples and frozensets

File D:\anaconda3\lib\site-packages\pandas\core\series.py:1069, in Series._get_value(self, label, takeable)
1066 return self._values[label]
1068 # Similar to Index.get_value, but we do not fall back to positional
→ 1069 loc = self.index.get_loc(label)
1070 return self.index._get_values_for_loc(self, loc, label)

File D:\anaconda3\lib\site-packages\pandas\core\indexes\multi.py:2869, in MultiIndex.get_loc(self, key, method)
2866 return mask
2868 if not isinstance(key, tuple):
→ 2869 loc = self._get_level_indexer(key, level=0)
2870 return _maybe_to_slice(loc)
2872 keylen = len(key)

File D:\anaconda3\lib\site-packages\pandas\core\indexes\multi.py:3222, in MultiIndex._get_level_indexer(self, key, level, indexer)
3218 return slice(i, j, step)
3220 else:
→ 3222 idx = self._get_loc_single_level_index(level_index, key)
3224 if level > 0 or self._lexsort_depth == 0:
3225 # Desired level is not sorted
3226 if isinstance(idx, slice):
3227 # test_get_loc_partial_timestamp_multiindex

File D:\anaconda3\lib\site-packages\pandas\core\indexes\multi.py:2802, in MultiIndex._get_loc_single_level_index(self, level_index, key)
2800 return -1
2801 else:
→ 2802 return level_index.get_loc(key)

File D:\anaconda3\lib\site-packages\pandas\core\indexes\base.py:3623, in Index.get_loc(self, key, method, tolerance)
3621 return self._engine.get_loc(casted_key)
3622 except KeyError as err:
→ 3623 raise KeyError(key) from err
3624 except TypeError:
3625 # If we have a listlike key, _check_indexing_error will raise
3626 # InvalidIndexError. Otherwise we fall through and re-raise
3627 # the TypeError.
3628 self._check_indexing_error(key)

KeyError: 0

Please give me some advices. Thanks a lot.

Pandas KeyError occurs when we try to access some column/row label in our DataFrame that doesn’t exist. Usually, this error occurs when you misspell a column/row name or include an unwanted space before or after the column/row name… Before doing anything with the data frame, use print(df.columns) to see dataframe column exist or not.


I was getting a similar kind of error in one of my codes. Turns out, that particular index was missing from my data frame as I had dropped the empty dataframe 2 rows. If this is the case, you can do df.reset_index(inplace=True) and the error should be resolved.