遍历熊猫数据框的所有元素?

时间:2018-12-14 14:41:45

标签: pandas loops dataframe

我正在尝试使用以下代码遍历4x3的数据框:

R = []
Ratio = pd.DataFrame(R)
for column in Three_Distances:
     column_location = Three_Distances.columns.get_loc(column)
     for rows, row in Three_Distances.iterrows():

         if column == 'post_one':
             Ratio[column_location,rows] = 
                   1/Three_Distances[column].divide(D1_theoretical)
         if column == 'post_two':
             Ratio[column_location,rows] = 
                   1/Three_Distances[column].divide(D2_theoretical)
         if column == 'post_three':
             Ratio[column_location,rows] = 
                  1/Three_Distances[column].divide(D3_theoretical)

我的变量Ratio输出是4x12而不是4x3。我想知道我是否不正确地理解我正在使用的工具或循环?

谢谢

0 个答案:

没有答案