Make a CSV formatting tool with Python Pandas PyInstaller

review

Installation of Python and Pandas

Days 1 and 2 of creating operation log formatting tool

CSV sort

Day 3 of creating operation log formatting tool

Column shaping, PyInstaller

Day 4 of creating operation log formatting tool

Create * .bat

test.bat


cd /d %~dp0

call firstpandas.exe

The same folder looks like this image.png

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.

Column existence check

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')

File encoding

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

Finally

formatter.bat


cd /d %~dp0

copy %1 in.csv

call ofmt.exe

echo "see out.csv!"

pause

It looks like this image.png

Recommended Posts

Make a CSV formatting tool with Python Pandas PyInstaller
Create "operation log" CSV formatting tool in 5 days with Python Pandas PyInstaller
Read csv with python pandas
Make a fortune with Python
Try to make a command standby tool with python
[Python] A memo to write CSV vertically with Pandas
Make apache log csv with python
Let's make a GUI with python.
Make a recommender system with python
Let's make a graph with python! !!
[5th] I tried to make a certain authenticator-like tool with python
Let's make a shiritori game with Python
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
Let's make a voice slowly with Python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
Let's make a web framework with Python! (1)
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
How to read a CSV file with Python 2/3
Make Python scripts into Windows-executable .exes with Pyinstaller
[Python] Make a game with Pyxel-Use an editor-
Read Python csv data with Pandas ⇒ Graph with Matplotlib
I want to make a game with Python
Try to make a "cryptanalysis" cipher with Python
[Python] Make a simple maze game with Pyxel
Let's replace UWSC with Python (5) Let's make a Robot
Try to make a dihedral group with Python
Make holiday data into a data frame with pandas
Make JSON into CSV with Python from Splunk
Csv tinkering with python
[Practice] Make a Watson app with Python! # 2 [Translation function]
Make a simple Slackbot with interactive button in python
Let's make a simple game with Python 3 and iPhone
How to convert JSON file to CSV file with Python Pandas
Process csv data with python (count processing using pandas)
What is God? Make a simple chatbot with python
[Super easy] Let's make a LINE BOT with Python.
[Python] Change dtype with pandas
Make Puyo Puyo AI with Python
Make a bookmarklet in Python
Write to csv with Python
Create a directory with python
Download csv file with python
Make a fire with kdeplot
Let's make a websocket client with Python. (Access token authentication)
Create a new csv with pandas based on the local csv
Associate Python Enum with a function and make it Callable
Experiment to make a self-catering PDF for Kindle with Python
Create a simple video analysis tool with python wxpython + openCV
Make a 2D RPG with Ren'Py (3) -Items and Tool Shop
[Python] Make a simple maze game with Pyxel-Make enemies appear-
I tried to make a generator that generates a C # container class from CSV with Python
[Python] What is a with statement?
[Python] Loading csv files using pandas
[Python] Make a graph that can be moved around with Plotly
Solve ABC163 A ~ C with Python
Operate a receipt printer with python
A python graphing manual with Matplotlib.