Date : March 29 2020, 07:55 AM
To fix this issue Given a text file file.txt containing for /f "usebackq tokens=1 delims= " %%a in ("file_path.txt") do echo %%a
|
Python: Read Pandas Dataframe from csv File, Make Filtered Output to Another File as csv
Tag : python , By : Roel van Dijk
Date : March 29 2020, 07:55 AM
I wish this helpful for you Don't attempt to write each line individually, dataframes have to_csv method. df = pd.read_csv('input.csv')
# some filtering logic, for example:
filtered_df = df[df['col a'] == 2]
filtered_df.to_csv('output.csv')
|
Tag : awk , By : usingtechnology
Date : March 29 2020, 07:55 AM
To fix the issue you can do Going by my understanding of your requirements, you want to use the tab-separated file to get the file names on column 1 and you want to add .txt extension to them and pass it to another file. Firstly use mapfile to get the names from the tab-separated file mapfile -t fileNames < <(awk -v FS="\t" '{print $1}' tabfile)
awk ... "${fileNames[@]/%/.txt}"
|
Make new txt file with size info of output and input files separately for each file
Date : March 29 2020, 07:55 AM
this one helps. Use os.path.splitext for remove extension of original files, also f.close() is not necessary, because with automatically close the file: import glob, os
import pandas as pd
files = glob.glob('*.csv')
#loop by all files
for file in files:
if not file.startswith(('output_','file_size_')):
#for write to parameter w
with open(os.path.splitext(file)[0] + "stats.txt", 'w') as f:
output_file_name = "output_" + file
#add both format
infile = 'SIZE OF INPUT FILE {} IS {}, '.format(file, os.path.getsize(file))
outfile = 'SIZE OF INPUT FILE {} IS {}'.format(output_file_name,
os.path.getsize(output_file_name))
f.write(infile)
f.write(outfile)
import glob, os
import pandas as pd
files = glob.glob('*.csv')
input_all, output_all = 0, 0
#loop by all files
for file in files:
if not (file.startswith('output_') or file.endswith('stats.txt')):
with open(os.path.splitext(file)[0] + "stats.txt", 'w') as f:
output_file_name = "output_" + file
#add both format
i = os.path.getsize(file)
o = os.path.getsize(output_file_name)
input_all += i
output_all += o
infile = 'SIZE OF INPUT FILE {} IS {}, '.format(file, i)
outfile = 'SIZE OF INPUT FILE {} IS {}'.format(output_file_name, o)
f.write(infile)
f.write(outfile)
with open("final_stats.txt", 'w') as f:
instring = 'SIZE OF ALL INPUT FILES IS {}, '.format(input_all)
outstring = 'SIZE OF ALL OUTPUT FILES IS {}, '.format(output_all)
both = 'SIZE OF ALL FILES IS {}'.format(input_all + output_all)
f.write(instring)
f.write(outstring)
f.write(both)
|
Date : March 29 2020, 07:55 AM
may help you . I would consider using pandas and write to csv. You can preserve the language format nicely as well import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
res = requests.get('https://www.wikipedia.org/')
soup = bs(res.content, 'lxml')
items = [item.text for item in soup.select('strong')][1:-1]
df = pd.DataFrame(items, columns = ['Languages'])
df.to_csv(r'C:\Users\User\Desktop\Wiki.csv', sep=',', encoding='utf-8-sig',index = False )
df.to_excel(r"C:\Users\User\Desktop\Wiki.xls", sheet_name='MyData', index = False, header=False)
|