In [2]:
#Create DataFrame
import pandas as pd
import numpy as np
from pandas import DataFrame, Series
df = DataFrame(
    {'integer':[1,2,3,6,7,23,8,3],
     'float':[2,3.4,5,6,2,4.7,4,8],
     'string':['saya',None,'aku','cinta','kamu','a','b','jika']}
)
df
Out[2]:
float integer string
0 2.0 1 saya
1 3.4 2 None
2 5.0 3 aku
3 6.0 6 cinta
4 2.0 7 kamu
5 4.7 23 a
6 4.0 8 b
7 8.0 3 jika
In [5]:
#Change value by index
df.ix[6,'string']='a'
df.ix[7,'string']='a'
df
Out[5]:
float integer string
0 2.0 1 saya
1 3.4 2 None
2 5.0 3 aku
3 6.0 6 cinta
4 2.0 7 kamu
5 4.7 23 a
6 4.0 8 a
7 8.0 3 a
In [6]:
#Grouping data in DataFrame
grouped = df['float'].groupby(df['string'])
grouped.mean()
Out[6]:
string
a         5.566667
aku       5.000000
cinta     6.000000
kamu      2.000000
saya      2.000000
Name: float, dtype: float64
In [15]:
df2 = df.copy()
def operation_more_than_one_columns(x):
    return x*2, x*3

df2['star_by_2'], df2['star_by_3'] = zip(*df2['integer'].map(operation_more_than_one_columns))
df2
Out[15]:
float integer string star_by_2 star_by_3
0 2.0 1 saya 2 3
1 3.4 2 None 4 6
2 5.0 3 aku 6 9
3 6.0 6 cinta 12 18
4 2.0 7 kamu 14 21
5 4.7 23 a 46 69
6 4.0 8 a 16 24
7 8.0 3 a 6 9
In [22]:
df3 = df.copy()
def sum_two_columns(series):
    return series['integer'] + series['float']

df3['sum_int_float'] = df3.apply(sum_two_columns,axis=1)
df3
Out[22]:
float integer string sum_int_float
0 2.0 1 saya 3.0
1 3.4 2 None 5.4
2 5.0 3 aku 8.0
3 6.0 6 cinta 12.0
4 2.0 7 kamu 9.0
5 4.7 23 a 27.7
6 4.0 8 a 12.0
7 8.0 3 a 11.0
In [ ]: