0

Data Science Last Code Project-Pandas Pandas Pandas

The Project called "Pandas Pandas Pandas", so I think it should be done by Pandas. It could be done completely by Pandas. But one issue is the output format. Only the Numpy array.round() could output the format like [4. 0.], which the trailing zero had been automatiically removed. ===================================================================== import pandas as pd import numpy as np n = int(input()) df_ori_cen = pd.DataFrame( {"cen_1st": [0, 0], "cen_2nd": [2, 2]}, index = [0, 1]) df_con_input = pd.DataFrame() for i in range(n): df_temp = pd.DataFrame( [float(x) for x in input().split()], columns = [i]) df_con_input = pd.concat([df_con_input, df_temp],axis = 1 ) df_first_cen = pd.DataFrame() df_second_cen = pd.DataFrame() for i in range(n): ed1 = sum((df_ori_cen["cen_1st"] - df_con_input[i])**2)**0.5 ed2 = sum((df_ori_cen["cen_2nd"] - df_con_input[i])**2)**0.5 if ed1 <= ed2: df_first_cen = pd.concat([df_first_cen, pd.DataFrame(df_con_input[i])], axis = 1) else: df_second_cen = pd.concat([df_second_cen, pd.DataFrame(df_con_input[i])], axis = 1) if df_first_cen.empty != True: new_cen_first = df_first_cen.mean(axis = 1) array_cen_first = np.round([*new_cen_first], 2) print(array_cen_first) else: print(None) if df_second_cen.empty != True: new_cen_second = df_second_cen.mean(axis = 1) array_cen_second = np.round([*new_cen_second], 2) print(array_cen_second) else: print(None)

1st Aug 2022, 10:48 PM
Yaodong Song
Yaodong Song - avatar
1 Respuesta
0
Yaodong Song So what is your question?
21st Jun 2023, 3:40 PM
Евгений
Евгений - avatar