#title Python - File에서 데이터 읽기 [[TableOfContents]] ==== 예제파일 ==== d:\pydata 디렉토리에 아래의 파일이 있다고 가정 * attachment:File에서데이터읽기/ex1.txt * attachment:File에서데이터읽기/ex2.txt ==== 예제1: 헤더가 존재하는 파일 읽기 ==== {{{ ex1 = pd.read_table("d:\pydata\ex1.txt", sep=",", header=0) ex1 ex1.columns ex1.index }}} ==== 예제2: 헤더가 존재하지 않는 파일 읽기, 헤더 추가하기 ==== 방법1 {{{ names = ["col1", "col2"] ex2 = pd.read_table("d:\pydata\ex2.txt", names=names, sep=",", header=None) ex2 }}} 방법2 {{{ ex2 = pd.read_table("d:\pydata\ex2.txt", sep=",", header=None) ex2.columns = ["col1", "col2"] ex2 }}} ==== 예제3: top n개만 읽기 ==== {{{ ex1 = pd.read_table("d:\pydata\ex1.txt", sep=",", header=0, nrows=2) ex1 }}} ==== 예제4: n개 skip하기 ==== {{{ ex1 = pd.read_table("d:\pydata\ex1.txt", sep=",", header=0, skiprows=2) ex1 }}} ---- CategoryMachineLearning