There is a question how to replace the values in the array with the necessary ones? I want if in the array the value is 9999, then replace it with 1, and the rest to replace it with 0. From the Excel file , another file is created.
import pandas as pd file_name = r'C:\Users\fazliakhmetovRV\Documents\Python Scripts\primer1.xlsx' out = r'C:\Users\fazliakhmetovRV\Documents\Python Scripts\result.xlsx' cols = ['metka','x','y','z','gk'] df = pd.read_excel(file_name, sheetname='er', skiprows=4, header=None, parse_cols='C:XFD') dfs = [] for i in range(df.columns.size//5): lbl_col = 5*i # filter each 5-column block x = df.ix[(df[lbl_col] != 0) & (df[lbl_col] != 9999), lbl_col:lbl_col+4] # set custom column names x.columns = cols # set 'metka' column as index (will be used for alignment by `pd.concat()`) x.index = x.metka dfs.append(x) # merge filtered DFs horizontally (aligned by indexes) result = pd.concat(dfs, axis=1) # replace all `metka` columns with the "most complete" list of labels result.ix[:, ::5] = pd.concat([result.index.to_series()] * (len(df.columns)//5), axis=1) # replace all NaN's with `9999` result.fillna(9999, inplace=True) # save resulting DF to Excel result.to_excel(out, index=False) From result.xlsx, the data is written into arrays:
n_met=len(result) n_well=result.columns.size/5 x=result.x.values.astype(int) y=result.y.values.astype(int) z=result.z.values.astype(int) gk=result.gk.values.astype(float) Next, I want to replace the values from 9999 with 1, and the remaining 0. As I understand it, you cannot do this):
for i in range(1,n_met): for j in range(1,n_well): if x[i][j]==9999: x[i][j]=1 else: x[i][j]=0 Please tell me how to realize this moment?

x? PS it's not entirely clear why you created all these variables:x,y,z,gk... - MaxU1and0in all columns exceptmetka? - MaxU