python pandas 文件读取pd.read_csv、pd.read_excel

一、读取

(1)read_csv

import  pandas as pd
 
mydata_txt  =  pd.read_csv( 'lucia_test.txt' , sep = '\n' , encoding = 'utf8' )
print (mydata_txt)


(2)pd.read_excel ##可以用help(pd.read_excel)来查询

#coding:utf-8import pandas as pd

import numpy as np

filefullpath = r"/home/geeklee/temp/all_gov_file/pol_gov_mon/downloads/1.xls"

#filefullpath = r"/home/geeklee/temp/all_gov_file/pol_gov_mon/downloads/26368f3a-ea03-46b9-8033-73615ed07816.xls"

df = pd.read_excel(filefullpath,skiprows=[0])

#df = pd.read_excel(filefullpath, sheetname=[0,2],skiprows=[0])

#sheetname指定为读取几个sheet,sheet数目从0开始#如果sheetname=[0,2],那代表读取第0页和第2页的sheet

#skiprows=[0]代表读取跳过的行数第0行,不写代表不跳过标题

#df = pd.read_excel(filefullpath, sheetname=None ,skiprows=[0])

df.head() #默认读取前5行 #aconda

type(df)

#若果有多页,type(df)就为

#如果就一页,type(df)就为

#{0:dataframe,1:dataframe,2:dataframe}



你可能感兴趣的:(Python)