2016-04-10 5 views
8

साथ dataframe पंक्ति को अद्यतन मैं एक पाठ फ़ाइल जो df1 = pandas.read_csv(r'fruits.txt', sep=',')पांडा नया मान

item freshness 
0 apple 2.2 
1 pear  0.0 

द्वारा पांडा में पढ़ा जा चुका है और उस apple = 2.3

का परिणाम प्राप्त होते हैं गणना की एक श्रृंखला है यह संभव है pandas.update करें ताकि मैं पर डेटाफ्रेम में apple के लिए freshness का मान अपडेट कर सकूं?

उत्तर

9

IIUC आप loc की जरूरत है:

apple = 2.3 

print df['item'] == 'apple' 
0  True 
1 False 
Name: item, dtype: bool 

df.loc[df['item'] == 'apple', 'freshness'] = apple 
print df 
    item freshness 
0 apple  2.3 
1 pear  0.0 
+1

धन्यवाद! वह आसान था .. लॉल –

संबंधित मुद्दे