In [1]:
import pandas as pd
import numpy as np
flnm = input('Input Data File(*.xlsx) = ')
with pd.ExcelFile(flnm) as data_fl:
data_df = pd.read_excel(data_fl)
K = int(input('K = ')) # Number of categories
c_nm = data_df.columns.values
df = pd.DataFrame()
for c in c_nm:
v = data_df[c].values
if v[0] == -1:
df['R_' + c] = K + 1 - data_df[c].values[1:]
else:
df[c] = data_df[c].values[1:]
with pd.ExcelWriter('R_' + flnm) as xl_writer:
df.to_excel(xl_writer, index = False)
print('The results were saved in', 'R_'+flnm)
The results were saved in R_Data.xlsx
In [ ]: