Here i'm just posing the part of the code which is throwing the error. Here i'm concating two different sets of dataframes that are appended in two different list.
path1 = '/home/Desktop/computed_2d_blaze/'
path2 = '/home/Desktop/computed_1d/'
path3 = '/home/Desktop/sn_airmass_seeing/'
dir1 = [x for x in os.listdir(path1) if '.ares' in x]
dir2 = [x for x in os.listdir(path2) if '.ares' in x]
dir3 = [x for x in os.listdir(path3) if '.ares' in x]
lst = []
lst1 = []
for file1, file2,file3 in zip(dir1,dir2,dir3):
df1 = pd.read_table(path1+file1, skiprows=0, usecols=(0,1,2,3,4,8),names=['wave','num','stlines','fwhm','EWs','MeasredWave'],delimiter=r'\s+')
df2 = pd.read_table(path2+file2, skiprows=0, usecols=(0,1,2,3,4,8),names=['wave','num','stlines','fwhm','EWs','MeasredWave'],delimiter=r'\s+')
df1 = df1.groupby('wave').mean().reset_index()
df1 = df1.sort_values('wave').reset_index(drop=True)
df2 = df2.sort_values('wave').reset_index(drop=True)
dfs = pd.merge(df1,df2, on='wave', how='inner')
dfs['delta_ew'] = (dfs.EWs_x - dfs.EWs_y)
dfs=dfs.filter(items=['wave','delta_ew'])
lst.append(dfs)
df3 = pd.read_table(path3+file3, skiprows=0, usecols=(0,1,2),names=['seeing','airmass','snr'],delimiter=r'\s+')
lst1.append(df3)
[df.set_index('wave', inplace=True) for df in lst]
df=pd.concat(lst,axis=1,join='inner')
x = pd.concat(lst1,axis=1,join='inner')
for z in df.index:
t = x.loc[0, 'airmass']
s = df.loc[z, 'delta_ew']
dfs = pd.concat([s,t],axis=1,names=['delta_ew','airmass'])
dfs = dfs[np.abs(dfs.delta_ew - dfs.delta_ews.mean()) <= (dfs.delta_ews.mad())]
As i trying to create a new dataframe as there are some outliers in delta_ew
so in order to remove them i'm doing this. But when tried to do this i got this error ValueError: cannot reindex from a duplicate axis
.
I don't understand how to solve this error. Can anyone tell me where i'm making mistake?
HERE'S THE FULL TRACEBACK
Traceback (most recent call last):
File "/home/gyanender/Desktop/r_values/airmass_vs_ew/delta_ew/for_rvalues.py", line 72, in <module>
dfs = pd.concat([s,t],axis=1,names=['delta_ew','airmass'])
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/reshape/concat.py", line 213, in concat
return op.get_result()
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/reshape/concat.py", line 385, in get_result
df = cons(data, index=index)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 330, in __init__
mgr = self._init_dict(data, index, columns, dtype=dtype)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 461, in _init_dict
return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 6168, in _arrays_to_mgr
arrays = _homogenize(arrays, index, dtype)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 6465, in _homogenize
v = v.reindex(index, copy=False)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/series.py", line 2681, in reindex
return super(Series, self).reindex(index=index, **kwargs)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/generic.py", line 3023, in reindex
fill_value, copy).__finalize__(self)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/generic.py", line 3041, in _reindex_axes
copy=copy, allow_dups=False)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/generic.py", line 3145, in _reindex_with_indexers
copy=copy)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/internals.py", line 4139, in reindex_indexer
self.axes[axis]._can_reindex(indexer)
File "/home/gyanender/.local/lib/python2.7/site-packages/pandas/core/indexes/base.py", line 2944, in _can_reindex
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis