Python 데이터 분석의 pandas 읽 기 데이터

2977 단어 pythonpandas
세 가지 데이터 파일 읽 기
在这里插入图片描述
csv,tsv,txt 파일 읽 기
1)CSV 파일 읽 기:
문법 형식:pandas.readcsv(파일 경로)
CSV 파일 내용 은 다음 과 같 습 니 다.
在这里插入图片描述

import pandas as pd
file_path = "e:\\pandas_study\\test.csv"
content = pd.read_csv(file_path)

content.head()  #      5   
content.head(3)  #    3   
content.shape  #       (   ,   ),         

content.index    #        ,         <class 'pandas.core.indexes.range.RangeIndex'>

content.column    #          Index(['  ', '  ', '  '], dtype='object')

content.dtypes  #             
      object
       int64
      object
dtype: object

2)CSV 파일 읽 기:
문법 형식:pandas.readcsv(파일 경로)
CSV 파일 내용 은 다음 과 같 습 니 다.
在这里插入图片描述

import pandas as pd
file_path = "e:\\pandas_study\\test2.txt"

content = pd.read_csv(file_path,sep='\t',header = None ,names= ['name','age','adress'])
#    :
# header = None        
# sep='\t'             
# names= ['name','age','adress'] ,        'name','age','adress'

content.head()  #      5   
content.head(3)  #    3   
content.shape  #       (   ,   ),         

content.index    #        ,         <class 'pandas.core.indexes.range.RangeIndex'>

content.column    #          Index(['  ', '  ', '  '], dtype='object')

content.dtypes  #             
3.엑셀 파일 읽 기
在这里插入图片描述

import pandas as pd
file_path = "e:\\pandas_study\\test3.xlsx"
content = pd.read_excel(file_path)

content.head()  #      5   
content.head(3)  #    3   
content.shape  #       (   ,   ),         

content.index    #        ,         <class 'pandas.core.indexes.range.RangeIndex'>

content.column    #          Index(['  ', '  ', '  '], dtype='object')

content.dtypes  #             
      object
       int64
      object
dtype: object
4.데이터베이스 표 읽 기
문법:pandas.readsql(sql 구문,데이터베이스 연결 대상)
데이터 대상 생 성,pymysql,cxOacle 등 모듈 은 my sql 이나 Oacle 을 연결 합 니 다.
파 이 썬 데이터 분석 에 관 한 pandas 읽 기 데이터 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 pandas 읽 기 데이터 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 지원 바 랍 니 다!

좋은 웹페이지 즐겨찾기