I have 2 DataFrames both countain countries 1-first have 183 row 2-the second have 156 row both of them has import information on each other I need one column from the first and one column from the second My goal is to create a single Dataframe contain both columns that I need and name of the contain that both datafames commo.
This is what I did and the message that I got
for i in range(183) :
for j in range(156):
if df['Country'][i]==df_happy['Country or region'][j]:
df.drop(i,axis=0,inplace=True)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-25-e078ef71e219> in <module>
1 for i in range(183) :
2 for j in range(156):
----> 3 if df['Country'][i]==df_happy['Country or region'][j]:
4 df.drop(i,axis=0,inplace=True)
/opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/pandas/core/series.py in __getitem__(self, key)
869 key = com.apply_if_callable(key, self)
870 try:
--> 871 result = self.index.get_value(self, key)
872
873 if not is_scalar(result):
/opt/conda/envs/Python-3.7-main/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_value(self, series, key)
4403 k = self._convert_scalar_indexer(k, kind="getitem")
4404 try:
-> 4405 return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))
4406 except KeyError as e1:
4407 if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
KeyError: 1