Days 1 and 2 of creating operation log formatting tool
Day 3 of creating operation log formatting tool
Day 4 of creating operation log formatting tool
test.bat
cd /d %~dp0
call firstpandas.exe
The same folder looks like this
There is a firstpandas.exe
that just reads in.csv
and makes it out.csv
.
The file I actually get is not in.csv, so I wonder if I should change the csv received as an argument with * .bat to in.csv.
By the way, there were several types of file formats, so I changed them.
How to check if a column exists in Pandas https://stackoverflow.com/questions/24870306/how-to-check-if-a-column-exists-in-pandas
firstpandas.py
import pandas as pd
df = pd.read_csv('oplog20201112.csv',encoding="SHIFT-JIS")
# print(df)
if 'Execution time' in df:
df_s = df.sort_values('Execution time')
df_s = df_s.reindex(columns=['Execution time',
'Function name',
'User ID',
'client name',
'Windows login ID',
'Terminal ID',
'Login time',
'Logout time'])
if 'PRC_DATE' in df:
df_s = df.sort_values('PRC_DATE')
df_s = df_s.reindex(columns=['PRC_DATE',
'DETAIL1',
'USERID',
'TERM_ID'])
df_s.to_csv('out.csv')
The following may appear.
UnicodeDecodeError: 'shift_jis' codec can't decode byte 0x87 in position 22224: illegal multibyte sequence
I thought,
Points to note when letting pandas read csv of excel output
https://minus9d.hatenablog.com/entry/2015/07/30/225841 https://stackoverflow.com/questions/6729016/decoding-shift-jis-illegal-multibyte-sequence
The encoding is further changed according to.
firstpandas.py
import pandas as pd
# df = pd.read_csv('in.csv',encoding="SHIFT-JIS")
df = pd.read_csv('in.csv',encoding="shift_jisx0213")
# print(df)
if 'Execution time' in df:
df_s = df.sort_values('Execution time')
df_s = df_s.reindex(columns=['Execution time',
'Function name',
'User ID',
'client name',
'Windows login ID',
'Terminal ID',
'Login time',
'Logout time'])
if 'PRC_DATE' in df:
df_s = df.sort_values('PRC_DATE')
df_s = df_s.reindex(columns=['PRC_DATE',
'DETAIL1',
'USERID',
'TERM_ID'])
df_s.to_csv('out.csv')
Other reference https://techacademy.jp/magazine/23367
formatter.bat
cd /d %~dp0
copy %1 in.csv
call ofmt.exe
echo "see out.csv!"
pause
It looks like this
Recommended Posts