概述
# -*- coding: utf-8 -*-
#coding:utf-8
import numpy as np
import pandas as pd
import string
df20105 = pd.read_csv('fbr_d_n_b.csv', delimiter = ',' , names = ['date','film','BoxOfficeReturn'])
df20105 = df20105
.dropna() #去掉NAN数据
# print df20105
val20105 = df20105.values
# print val20105
lst00 = []
for i in range(0,len(val20105)):
x = val20105[i][0] #请填入4位数字 取出日期
lx = x.
split('-')
lst00.append(lx[0]+lx[1]+lx[2])
df20105.index=lst00
# print df20105.index
df20105 = df20105.
drop(['date'], axis = 1) #删除原来日期的那一列
# df20105.to_csv('a.csv',index='True',encoding='utf-8')
# print type(val20105)
# print df20105[(df20105.index ==' 20100523')&(df20105.BoxOfficeReturn>10000)]
# print df20105[(df20105.index == ' 20100516') & (df20105.film == '让子弹飞')]
# rs1=df20105['BoxOfficeReturn'].
groupby([df20105.index,df20105['film']]).mean()
# print rs1
# df = df20105.mean(columns = 'BoxOfficeReturn')
# print df
# '''
# print df20105.columns
# print df20105.describe
# print df20105
# '''
#df20105 = df20105.sort_index()
#print df20105
# print type(val20105)
# df = df20105[(df20105.index == 20100523)&(df20105["BoxOfficeReturn"]>10000)]
# df = df20105[(df20105.BoxOfficeReturn>10000)]
# df = df20105[(df20105.index == 20100516) & (df20105.film == '让子弹飞')]
# print df
# 将日期转换成周数
lsa=df20105.index
lsb=[]
lsyct=[0,31,28,31,30,31,30,31,31,30,31,30,31]
sumdays=0
t=0
y=0
m=0
d=0
for da in lsa:
y=string.atoi(da)/10000
m=string.atoi(da)/100%100
d=string.atoi(da)%100
sumdays=0
for t in lsyct[0:m]:
sumdays += t
sumdays=(sumdays+d-2+((y%4==0 and y%100!=0 or y%400==0) and m > 2))/7
lsb.append("第"+`sumdays`+"周")
df20105.index=lsb
df20105n=df20105.reindex() #50ans: df2015n.reindex()
print df20105n #
# df20105n=df20105n.sort_index(by=None) #50ans: index
# rs1=df20105n['BoxOfficeReturn'].groupby([df20105n.index,df20105n['film']]).mean()
# rs2=df20105n['BoxOfficeReturn'].groupby([df20105n.index,df20105n['film']]).sum()
# print rs1 #平均
# print rs2 #求和
#57ans: index
#58ans: film
最后
以上就是安详戒指为你收集整理的电影样题的数据清洗的全部内容,希望文章能够帮你解决电影样题的数据清洗所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复