Importing and exporting data python fourth day of learning

1, import data (csv files)

import pandas
from pandas import read_csv
df = read_csv(''E://学习//python//4//4.8//data.csv',sep='|')

2, import txt file

Import read_table PANDAS from 

df = read_table ( 'data file stored position') 

or 

df = read_table ( 'data file location', names = [ 'age' , 'name'], sep = ',')

3, import excel file

Import read_excel PANDAS from 
DF = read_excel ( 'file storage location // filename .xlsx', sheetname = 'data' )

4、UTF-8

# coding UTF-8

from pandas import read_table;
from pandas import DataFrame;

df = read_table('D://Python//2.3//中文.txt', sep=',', encoding='UTF-8')
df

  5, export data to a csv file format

PD PANDAS AS Import 

gb.to_csv ( 'E: \\ \\ python \\ 5 \\ learning draw bar \\ data1.csv', encoding = 'utf -8') # gb where the data is to be exported name

  6, data export excel file format

PD PANDAS AS Import 

Import openpyxl 

gb.to_excel ( 'E: \\ \\ python \\ 5 \\ learning draw bar \\ data1.csv', encoding = 'utf -8', index = 'false') # equal to false means to remove the column name is derived

  

Guess you like

Origin www.cnblogs.com/manjianlei/p/11266313.html