python数据读取和存储

  1. open? 用于学习
  2. fp = open(‘D:/python-data/text.csv’,‘w’,newline=’’)
    writer = csv.writer(fp)
    writer.writerow((‘id’,‘name’,‘grade’))
    writer.writerow((‘1’,‘lucky’,‘87’))
    writer.writerow((‘2’,‘peter’,‘92’))
    writer.writerow((‘3’,‘lili’,‘85’))
    fp.close()
  3. df1=pd.read_csv(open(‘D:/python-data/数据/ch4ex3.csv’),header=None)
chunker= pd.read_csv(open('D:/python-data/数据/titanic.csv'),chunksize=100)
sex = Series([],dtype='float64')
for i in chunker:
    sex = sex.add(i['Sex'].value_counts(),fill_value=0)
sex
  1. df = pd.read_table(open(‘D:/python-data/数据/ch4ex7.txt’),sep=’\s+’)
    匹配多个空格
  2. df.to_csv(‘D:/python-data/数据/out2.csv’,sep=’?’)
  3. import json
    f=open(‘D:/python-data/数据/eueo2012.json’)
    obj = f.read()
    result = json.loads(obj)
    result
  4. import pandas as pd
    df = pd.read_json(‘D:/python-data/数据/eueo2012.json’)
    df
import pandas as pd
df = pd.read_excel('D:/python-data/数据/ch4ex8.xlsx',sheet_name='Sheet1')
df
  1. df.to_excel('D:/python-data/数据/out5.xlsx',sheet_name='out',index=None)
  2. from matplotlib import font_manager as fm, rcParams import matplotlib as plt
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文标签
plt.rcParams['axes.unicode_minus']=False   #这两行需要手动设置

你可能感兴趣的:(学习,python,数据挖掘)