目录
CSV(Comma-SeparatedValues)格式的文件是指以纯文本形式存储的表格数据,这意味着不能简单的使用Excel表格工具进行处理,而且Excel表格处理的数据量十分有限,而使用Pandas来处理数据量巨大的CSV文件就容易的多了。
importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK')#printdata.head()#printdata.tail()#作为示例,输出CSV文件的前5行和最后5行,这是pandas默认的输出5行,可以根据需要自己设定输出几行的值详细read_csv参数连接header=0表示文件第0行(即第一行,索引从0开始)为列索引,这样加names会替换原来的列索引。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',header=0)print(data)header=None即指明原始文件数据没有列索引,这样read_csv为自动加上列索引,除非你给定列索引的名字。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',header=None)print(data)names指定列名importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',names=['name','age','sex'])print(data)index_col:int类型值,序列,FALSE(默认None)将真实的某列当做index(列的数目,甚至列名)importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',index_col=0)print(data)nrows需要读取的行数(从文件头开始算起)如何存储csvto_csv()详细to_csv参数连接序列化pickle主要用于将python对象和文件之间的转换。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',nrows=2)#data=pd.read_table('../one.csv',encoding='GBK',sep=',',header=None)data.to_pickle('csv_data')result=pd.read_pickle('csv_data')print(result)使用数据库importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',header=0)print(data)header=None即指明原始文件数据没有列索引,这样read_csv为自动加上列索引,除非你给定列索引的名字。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',header=None)print(data)names指定列名importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',names=['name','age','sex'])print(data)index_col:int类型值,序列,FALSE(默认None)将真实的某列当做index(列的数目,甚至列名)importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',index_col=0)print(data)nrows需要读取的行数(从文件头开始算起)如何存储csvto_csv()详细to_csv参数连接序列化pickle主要用于将python对象和文件之间的转换。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',nrows=2)#data=pd.read_table('../one.csv',encoding='GBK',sep=',',header=None)data.to_pickle('csv_data')result=pd.read_pickle('csv_data')print(result)使用数据库importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',header=None)print(data)names指定列名importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',names=['name','age','sex'])print(data)index_col:int类型值,序列,FALSE(默认None)将真实的某列当做index(列的数目,甚至列名)importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',index_col=0)print(data)nrows需要读取的行数(从文件头开始算起)如何存储csvto_csv()详细to_csv参数连接序列化pickle主要用于将python对象和文件之间的转换。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',nrows=2)#data=pd.read_table('../one.csv',encoding='GBK',sep=',',header=None)data.to_pickle('csv_data')result=pd.read_pickle('csv_data')print(result)使用数据库importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',names=['name','age','sex'])print(data)index_col:int类型值,序列,FALSE(默认None)将真实的某列当做index(列的数目,甚至列名)importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',index_col=0)print(data)nrows需要读取的行数(从文件头开始算起)如何存储csvto_csv()详细to_csv参数连接序列化pickle主要用于将python对象和文件之间的转换。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',nrows=2)#data=pd.read_table('../one.csv',encoding='GBK',sep=',',header=None)data.to_pickle('csv_data')result=pd.read_pickle('csv_data')print(result)使用数据库importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',index_col=0)print(data)nrows需要读取的行数(从文件头开始算起)如何存储csvto_csv()详细to_csv参数连接序列化pickle主要用于将python对象和文件之间的转换。importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',nrows=2)#data=pd.read_table('../one.csv',encoding='GBK',sep=',',header=None)data.to_pickle('csv_data')result=pd.read_pickle('csv_data')print(result)使用数据库importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
nrows需要读取的行数(从文件头开始算起)
如何存储csvto_csv()详细to_csv参数连接
pickle主要用于将python对象和文件之间的转换。
importpandasaspddeftest():data=pd.read_csv('../one.csv',encoding='GBK',nrows=2)#data=pd.read_table('../one.csv',encoding='GBK',sep=',',header=None)data.to_pickle('csv_data')result=pd.read_pickle('csv_data')print(result)使用数据库importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
importpymysqlimportpandasaspddeftest():cOnn=pymysql.connect("localhost","root","admin","data_output")sql='SELECT*fromold_user'df=pd.read_sql(sql,conn)print(df)合并数据集博客连接重塑和轴向旋转数据转换
博客连接