Python学习笔记--pandas

import pandas as pd

1、通过字典创建数据框DataFrame

import pandas as pd

df = pd.DataFrame({'key' : ['b','b','a','c','a','b','a'], 'data1' : range(7)})

2、pandas 读取csv

import pandas as pd

one=pd.read_csv(r'/Users/dapeng/Documents/user_kmeans/Python_book/3Programing/One.csv',sep=",")

3、设置工作目录

#设置工作目录

import pandas as pd

import os

os.chdir(r'/Users/dapeng/Documents/user_kmeans/Python_book/3Programing')

one=pd.read_csv('One.csv')

4、pandas 读取Excel

import pandas as pd

xls = pd.read_excel('hsb2.xlsx', sheet_name=0)

xls = pd.read_excel('hsb2.xlsx', sheet_name=‘hsb2’)

sheet_name:指定表格的第几个sheet,默认第一个,可以传递整数,也可以传递sheet的名称。


5、导出数据写入csv

xls.to_csv('copyofhsb2.csv')

PS : 文中资料免费获取地址:https://www.yuque.com/buliangren-ggoez/ow7q27/kl28kc

你可能感兴趣的:(Python学习笔记--pandas)