#!/usr/bin/env python3a
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 15 15:37:40 2019
@author: lg
"""
import os
import pandas as pd
from pymongo import MongoClient
client=MongoClient('localhost',27017)
db=client.glory.snapshot
def file_name(file_dir):
# v=[]
for root, dirs, files in os.walk(file_dir):
# print('root_dir:', root) # 当前目录路径
# print('sub_dirs:', dirs) # 当前路径下所有子目录
print('files:', files) # 当前路径下所有非目录子文件
return files
c=file_name('./')
def save_data(df):
num=df.shape[0]
print('num=',num)
for q in range(num):
if q %10000==0:
print(round(q/num,3))
m=df.loc[q]
m1=dict(m)
if str( m1['giftbag_id']) not in ['nan','None'] :
m1['giftbag_id']=int(m1['giftbag_id'])
#
m1['player_id']=int(m1['player_id'])
db.save(m1)
# db.replace_one({'player_id':m1['player_id'],'timestamp':m1['timestamp']},
#
# m1,True
# )
kk=[]
for m in c:
dt=pd.read_csv(m)
ll=[ 'player_id', 'giftbag_id', 'status', 'timestamp', 'operation']
dt1=dt[ll]
save_data(dt1)
# kk.append(dt)
# print(m)
#
#m=pd.concat(kk)
#m.to_csv('eco.csv',index=False)
import os
import pandas as pd
def file_name(file_dir):
# v=[]
for root, dirs, files in os.walk(file_dir):
# print('root_dir:', root) # 当前目录路径
# print('sub_dirs:', dirs) # 当前路径下所有子目录
print('files:', files) # 当前路径下所有非目录子文件
return files
c=file_name('./')
kk=[]
for m in c:
dt=pd.read_csv(m)
kk.append(dt)
print(m)
m=pd.concat(kk)
m.to_csv('eco.csv',index=False)