๐Ÿ Excel RPA ์ž‘์—…์„ ์œ„ํ•œ Python Scripts ์™€ Pandas

UiPath python script ํ˜ธ์ถœ, parameter์ „๋‹ฌ, dataframe2datatable

Posted by labft3231 on May 12, 2020

pythonScript

์‚ฌ๋ฌด์—…์— ์žˆ์–ด์„œ excel์€ ๋‹ค์–‘ํ•œ ๋ถ„์•ผ์—์„œ ํ™œ์šฉ๋˜๊ณ  ์žˆ๊ณ , ์‚ฌ๋ฌด ์ž๋™ํ™”๋ฅผ ์œ„ํ•œ RPA์—์„œ๋„ excel์ด ๋งŽ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. UiPath์—์„œ๋„ ๋‹ค์–‘ํ•œ excel ์ฒ˜๋ฆฌ ๊ธฐ๋Šฅ์ด ์žˆ์ง€๋งŒ ๋ฐฉ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋น ๋ฅด๊ฒŒ ์ฒ˜๋ฆฌํ•ด์ค„ ์ˆ˜ ์žˆ๋Š” Pandas๋ฅผ ํ™œ์šฉํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค. ๋˜ python์œผ๋กœ ์›น crawling๋“ฑ์˜ ๋‹ค์–‘ํ•œ ์ž‘์—…์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— script ์ ์šฉ ์‹œ ํฐ ํž˜์„ ๋‚ผ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

ํ•ด๋‹น ํฌ์ŠคํŒ…์˜ ๋‹จ๊ณ„๋Š” 3๋‹จ๊ณ„๋กœ ๋‚˜๋ˆ„์–ด์ง‘๋‹ˆ๋‹ค.

  1. python ์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰
  2. python method์— ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ
  3. pandas ํ™œ์šฉ


webopen.xaml (uipath python script ์‹คํ–‰)

python_activity1

๋‹จ์ˆœํžˆ ์‹คํ–‰์„ ์œ„ํ•ด์„œ python๋ฒ„์ „ ์ •๋ณด์™€ ๊ฒฝ๋กœ๋“ฑ์„ ์ง€์ •ํ•ด์•ผํ•จ ์ด๊ฒƒ์„ python scope์—์„œ ํ•จ ๊ทธ ํ›„ ์‹คํ–‰ํ•  script๋ฅผ ์„ค์ •ํ•˜๋Š”๋ฐ ์ด๊ฑด load python script์—์„œ ์ง€์ • ๊ฐ€๋Šฅํ•จ ๋‹จ ๋ฉ”์†Œ๋“œ๋กœ ํ˜ธ์ถœํ•  ๊ฒฝ์šฐ ์•„๋ž˜ ์กฐ๊ฑด(main.xaml)์˜ activity๊ฐ€ ํ•„์š”ํ•จ



main.xaml (uipath python method ์‹คํ–‰)

python_activity2

Python Scope : ์„ค์น˜๋œ python ์ •๋ณด๋ฅผ ์ฝ์Œ(python์„ค์น˜๊ฒฝ๋กœ, os๋ฒ„์ „, python version) Load Python script : ํŒŒ์ด์ฌ script๋ฅผ ์ฝ์–ด ๊ฐ์ฒด์ €์žฅ (input: ์ฝ”๋“œ๋‚˜ ์‹คํ–‰ํ•  python script๋ช… / output: LoadedScript - python objectํ˜• ๊ฒฐ๊ณผ) Invoked Python method : ๊ฐ์ฒด๋ฅผ ๋ฐ›์•„ method์™€ ํŒŒ๋ผ๋ฏธํ„ฐ ์ง€์ • ํ•˜์—ฌ method ๊ฐ์ฒด ๋ฆฌํ„ด (input: LoadedScript - python objectํ˜• ๊ฒฐ๊ณผ, ์‹คํ–‰ํ•  python ํ•จ์ˆ˜์— parameter์™€ ํŒŒ์ผ๋ช…๊ณผ ํ•จ์ˆ˜๋ช… / output : python objectํ˜• ๊ฒฐ๊ณผ) Get python object : method ๊ฐ์ฒด ๋ฐ›์•„์„œ return ํƒ€์ž…๊ณผ return ๋ณ€์ˆ˜์— ์ง€์ • (input: MethodResult / ์˜ค๋ธŒ์ ํŠธ์—์„œ ๋ฐ›์„ ๋ฐ์ดํ„ฐ ํ˜•ํƒœ, ๋ฐ์ดํ„ฐ ํ˜•ํƒœ์— ๋งž๋Š” result๋ณ€์ˆ˜)



testDF(uipath pandas ํ™œ์šฉ DataFrame TO DataTable)

1
2
3
4
5
6
7
8
import pandas as pd

def executionDF():
    s1 = pd.core.series.Series( [1, 2, 3, 4, 5] )
    s2 = pd.core.series.Series( ["one", "two", "three", "four", "five", "six", "seven"])
    df = pd.DataFrame(data=dict(num=s1, word=s2, a=''))
    return df.to_json(orient='records')

Pandas์˜ DataFrame์„ ๋ฐ”๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ๊ฐ€ ์—†์–ด .py์—์„œ json์„ ๋ฆฌํ„ดํ•ด์ฃผ๊ณ  json์œผ๋กœ datatable๋กœ ๋ณ€ํ™˜

python์—์„œ excel๋กœ ์ €์žฅํ•˜๊ณ  excelํŒŒ์ผ์„ uipath์—์„œ ์ฝ์–ด๋„ ์ƒ๊ด€์—†์Œ (ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ์ „์ž์˜ ๋ฐฉ๋ฒ•์œผ๋กœ ํ–ˆ์Œ)

https://github.com/labft3231/pythonScript ๐Ÿ‘ˆ โ€œ๐Ÿ Python Scripts AND Pandas Basic / UiPath์—์„œ Pandas๋ฅผ ํ™œ์šฉํ•œ excel ๋ฐ์ดํ„ฐ ์กฐ์ž‘์ž…๋‹ˆ๋‹ค.โ€