我假设 Ubuntu 拥有 Python 所需的所有软件包。我的意思是 Python3。我安装了 PyCharm。我刚刚运行了这个import pandas as pd
,得到了no module found
错误。我很惊讶。这是否意味着我必须从头开始安装所有软件包?如果是这样,如何安装它们?
更新:
我的文本文件不正确,其中包含产品名称、网站位置和数量。现在我只想准备产品名称、编号(从 URL 中提取)和数量。
输入文件:
rawfile.txt
Component name Link Quantity
Ba Test Con - Red https://kr.element14.com/multicomp/a-1-126-n-r/banana-plug-16a-4mm-cable-red/dp/1698969 25
Ban Te Con - Black https://kr.element14.com/multicomp/a-1-126-n-b/plug-16a-4mm-cable-black/dp/1698970 25
Ban Te Con - Black https://kr.element14.com/hirschmann-testmeasurement/930103700/socket-4mm-black-5pk-mls/dp/1854599 15
预期输出:
Ba Test Con - Red 1698969 25
Ban Te Con - Black 1698970 25
Ban Te Con - Black 1854599 15
我的代码:
For product name:
# extract product name
grep '.*?(?=https://)' rawfile.txt
# extract product number
grep -Po '\b[0-9]{6,7}\t\b' rawfile.txt
# extract quanity
grep -Po '\t[0-9]{1,3}' rawfile.txt
# Now combining the last two functions into one ; this works
# grep -Po '(number argument)(quantity argument)' rawfile.txt
grep -Po '(\b[0-9]{6,7}\t\b)(\t[0-9]{1,3})' rawfile.txt
1698969 25
1698970 25
1854599 15
# Now combining the three functions into one and producing an output text file; this works
# grep -Po '(product name argument)(number argument)(quantity argument)' rawfile.txt
grep -Po '(.*?(?=https://))(\b[0-9]{6,7}\t\b)(\t[0-9]{1,3})' rawfile.txt
目前的输出:
>> grep -Po '(.*?(?=https://))(\b[0-9]{6,7}\t\b)(\t[0-9]{1,3})' rawfile.txt
>> # no output