vmamontov

simple

Aug 5th, 2021
579
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import random
  3.  
  4. data_1 = random.sample(range(200, 500), 20)
  5. data_2 = random.sample(range(100, 500), 20)
  6. data_3 = random.sample(range(200, 500), 20)
  7.  
  8. df_1 = pd.DataFrame(data_1, columns=["num_1"])
  9. df_2 = pd.DataFrame(data_2, columns=["num_2"])
  10. df_3 = pd.DataFrame(data_3, columns=["num_3"])
  11.  
  12. df_1 = df_1.join([df_2, df_3], how='left')
  13. df_1['max'] = '-'
  14.  
  15. list_columns = df_1.columns
  16. # print(list_columns)
  17. display(df_1)
  18.  
  19. for i in range(len(df_1)):
  20.     list_values = list(df_1.loc[i, "num_1":"num_3"])
  21.     max_value = max(list_values)
  22.     index_max = list_values.index(max_value)
  23.     # print(max_value, index_max)
  24.     df_1.loc[i, "max"] = list_columns[index_max]
  25.  
  26. display(df_1)
RAW Paste Data