Rewrite SPSS Modeler filter nodes in Python

Try rewriting the filter node in Python pandas to narrow down the columns or change the column name with SPSS Modeler.

1. Image of processing

Delete the UP_TIME and ERR_CD columns of the following data, Change the column name "M_CD" to "MCD" and the column name "POWER" to "VOLT".

■ Before processing

image.png

■ After processing

image.png

2. Designation in the Modeler filter node

Check the box you want to delete and write the name you want to change in the field name field on the right. image.png

3. Rewrite with pandas

There are several column choices, but the first is to list the column names you want to keep in the list, as shown below.

df1=df[['M_CD','POWER','TEMP']]

There is also a method called drop that specifies the column you want to delete. This may be closer to the image of the Modeler filter.

df1_1=df.drop(['UP_TIME','ERR_CD'],axis=1)

Both methods return the following results.

image.png

Next, you can use a method called rename to change the column name. Gives a set of column names before and after the change in the dictionary.

df2=df1.rename(columns={'M_CD': 'MCD', 'POWER': 'VOLT'})

The following result will be returned.

image.png

4. Sample

The sample is placed below.

stream https://github.com/hkwd/200611Modeler2Python/raw/master/filternode/FilterNode.str notebook https://github.com/hkwd/200611Modeler2Python/blob/master/filternode/FilterNode2.ipynb

■ Test environment Modeler 18.2.1 Windows 10 64bit Python 3.6.9 pandas 0.24.1

5. Reference site

Select and get rows / columns by pandas index reference | note.nkmk.me https://note.nkmk.me/python-pandas-index-row-column/ Change row name / column name of pandas.DataFrame | note.nkmk.me https://note.nkmk.me/python-pandas-dataframe-rename/

Recommended Posts

Rewrite SPSS Modeler filter nodes in Python
Rewrite field order nodes in SPSS Modeler with Python.
Filter List in Python
Rewrite SPSS Modeler reconfigure node in Python. Aggregation by purchased product category
Using Python with SPSS Modeler extension nodes ① Setup and visualization
Rewrite the record addition node of SPSS Modeler with Python.
Change node settings in supernodes with SPSS Modeler Python scripts
Rewrite duplicate record nodes in SPSS Modeler in Python. ① Identify the item you purchased first. (2) Identification of the top-selling item in the product category
How to pass arguments to a Python script in SPSS Modeler Batch
Rewrite the sampling node of SPSS Modeler with Python (2): Layered sampling, cluster sampling
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
I implemented Robinson's Bayesian Spam Filter in python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Rewrite relative links in html to absolute links in python (lxml)
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python