2017-02-09 11 views
2

Ich versuche, eine neue Spalte in einem Pandas Datenrahmen hinzufügen möchten, dann für Zeile den Wert der Spalte Zeile aktualisieren:Pandas. Wie eine neue Pandas Spalte Zeile für Zeile aktualisieren

my_df['col_A'] = 0 
    for index, row in my_df.iterrows(): 

     my_df.loc[index]['col_A'] = 100 # value here changes in real case 
     print(my_df.loc[index]['col_A']) 

    my_df 

jedoch aus im Druck , alle Werte im col_A sind immer noch 0, warum ist das so? Was habe ich verpasst? Vielen Dank!

Antwort

5

Sie in dieser Zeile zu einer Scheibe zuweisen my_df.loc[index]['col_A'] = 100

Stattdessen tun

my_df['col_A'] = 0 
for index, row in my_df.iterrows(): 

    my_df.loc[index, 'col_A'] = 100 # value here changes in real case 
    print(my_df.loc[index]['col_A']) 
Verwandte Themen