1. create dataframe 几种方式
1.1
import pandas as pd
df1= pd.DataFrame({'a':range(3),'b':range(3)})
2. 遍历一列
l = [str(v) for v in df.a]
print l
3.常用操作
切片
db= da.loc[:,['a','b',]]
聚合
db = da_38.groupby(['a']).sum()
过滤
da = da[(da.a==1) | (da.b==1)]
添加一列
d1['c'] = d1['a']/d1['b']
apply
d2['c'] = d2['a'].apply(lambda x: 1)
da["b"]=da.a.apply(lambda x: "a" if "a" in x else "b" if "b" in x else "")
存储
da.to_csv('/tmp/test.txt',sep='\t')
连接mysql
import MySQLdb
conn = MySQLdb.connect(host="", user="", passwd="", db="")
da = pd.read_sql("""select * from mytable""",conn)