Skip to content

Instantly share code, notes, and snippets.

/reloading line
Created Dec 7, 2017

Embed
What would you like to do?
GIO type
import csv
import numpy as npy
import pandas as pd
import os.path
import os
#
# data = pd.read_csv('C:/Program Files/R/Data/Normal123/N_13_3p/Normal/3p (1).txt', header = None)
# print data
#
#
# for i in range(len(data)):
# dfList = list(pd.read_csv(data[i]))
#
working_dir = "C:/Program Files/R/Data/Normal123/N_13_3p/Normal"
for root, dirs, files in os.walk(working_dir):
file_list = []
for filename in files:
if filename.endswith('.txt'):
file_list.append(os.path.join(root, filename))
data = [[] for i in range(2092)]
for file in file_list:
f = open(file)
lines = f.readlines()
for ln,line in enumerate(lines):
l = (line[:-2]).split(' ')
l = l[:12]+l[14:]
data[ln].append([float(a) for a in (l)])
# print df_list
#item = df_list[1].loc[0,0].split(" ")
#print item[0]
# delete a line with ctrl + y
#dfList = [pd.read_csv(files[i]) for i in range(len(files))]
#An even better solution is to drop the range:
#dfList = [pd.read_csv(file) for file in files]
##----------------------------------
import csv
import numpy as npy
import pandas as pd
import os.path
import os
#
# data = pd.read_csv('C:/Program Files/R/Data/Normal123/N_13_3p/Normal/3p (1).txt', header = None)
# print data
#
#
# for i in range(len(data)):
# dfList = list(pd.read_csv(data[i]))
#
working_dir = "C:/Program Files/R/Data/Normal123/N_13_3p/Normal"
for root, dirs, files in os.walk(working_dir):
file_list = []
for filename in files:
if filename.endswith('.txt'):
file_list.append(os.path.join(root, filename))
data = []
for file in file_list:
f = open(file)
lines = f.read()
df_list = [pd.read_table(file,header = None) for file in file_list]
if df_list:
final_df = pd.concat(df_list)
final_df.to_csv(os.path.join(root, "Final.csv"))
# print df_list
print len(df_list[1][0])
for pn,pack in enumerate(df_list):
for ln,line in enumerate(pack):
if(pn==1):
print line
#item = df_list[1].loc[0,0].split(" ")
#print item[0]
# delete a line with ctrl + y
#dfList = [pd.read_csv(files[i]) for i in range(len(files))]
#An even better solution is to drop the range:
#dfList = [pd.read_csv(file) for file in files]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.