利用Pandas库读取CSV文件

1.读取数据:

You need to use a package called ‘Pandas’ to read the ‘csv’ file.

In addition,you must import the package before using it.

import pandas as pd
file_path='./files/data.csv'
data=pd.read_csv(file_path,encoding='UTF-8')

Final you can use some functions to view some attributes of the data.

print('数据类型:'.format(type(data))) 

数据类型:DataFrame

2.利用Pandas库抽取数据:

first_data=data[u'列名']
print('抽取数据类型:'.format(type(first_data)))

抽取数据类型:Serise

for example the package have a simple command to get the first five pieces of data.

print(first_data.head())

2.写入CSV文件

This way allows you to write some information to files.

save_path='./Test.csv'
data.to_csv(save_path, index=0, encoding='UTF-8')

你可能感兴趣的:(数据分析)