文件读取与写入
1csv文件
df = pd.read_csv('data/table.csv')
df.to_csv('data/new_table.csv')
2txt文件
df_txt = pd.read_table('data/table.txt')
3xls和xlsx文件
df_excel = pd.read_excel('data/table.xlsx')
df.to_excel('data/new_table2.xlsx')
Series
Series 是一个类数组的数据结构。对于一个Series,其中最常用的属性为值(values),索引(index),名字(name),类型(dtype)
1最简单的Series对象,因为没有给Series指定索引,所以此时会使用默认索引
a=pd.Series([1,6,2,5,7])
2生成一个指定索引的Series
a=pd.Series([1,6,2,5,7],index=['w','a','l','x','a'])
3也可以通过字典来创建Series对象
用字典创建的Series是按index有序的
a={'w':2001,'a':1314,'l':2000}
a=pd.Series(a)
在用字典生成Series的时候,也可以指定索引,当索引中值对应的字典中的值不存在的时候,则此索引的值标记为Missing,NA,并且可以通过函数(pandas.isnull,pandas.notnull)来确定哪些索引对应的值是没有的
a={'w':2001,'a':1314,'l':2000}
b=['w','a','