티스토리 뷰

 

<결과>

24.0
27

<소스 코드>

def Test_DataFrame2():
    from pandas import DataFrame
    data11 = {
        'a1': 11,
        'b1': "12"
    }
    data12 = {
        'a1': 21,
        'b1': "22"
    }
    data13 = {
        'a1': 31,
        'b1': "32"
    }
    data14 = {
        'a1': 41,
        'b1': "42"
    }

    dataDF = DataFrame()
    dataDF = dataDF.append(data11, ignore_index=True)
    dataDF = dataDF.append(data12, ignore_index=True)
    dataDF = dataDF.append(data13, ignore_index=True)
    dataDF = dataDF.append(data14, ignore_index=True)
    index11 = dataDF.index[dataDF['b1']=="22"].tolist()
    if index11:
        dataDF.loc[index11[0], 'a1'] += 3
        value11 = dataDF.loc[index11[0], 'a1']
        print(value11)
        value12 = int(dataDF.loc[index11[0], 'b1']) + 5
        print(value12)

    print(data14)
반응형