GVKun编程网logo

Python:从字符串中提取唯一的句子并将它们放在用 ;(python在一串字符中提取指定的字符)

4

此处将为大家介绍关于Python:从字符串中提取唯一的句子并将它们放在用;的详细内容,并且为您解答有关python在一串字符中提取指定的字符的相关问题,此外,我们还将为您介绍关于/System/Lib

此处将为大家介绍关于Python:从字符串中提取唯一的句子并将它们放在用 ;的详细内容,并且为您解答有关python在一串字符中提取指定的字符的相关问题,此外,我们还将为您介绍关于/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”、CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取、Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod、Error: Can‘t find Python executable “python“, you can set the PYTHON env variable的有用信息。

本文目录一览:

Python:从字符串中提取唯一的句子并将它们放在用 ;(python在一串字符中提取指定的字符)

Python:从字符串中提取唯一的句子并将它们放在用 ;(python在一串字符中提取指定的字符)

如何解决Python:从字符串中提取唯一的句子并将它们放在用 ;

下午的 Stackoverflowers,

我遇到了一些提取/的挑战,因为我正在尝试为一些用户准备数据。 我被告知,在 sql 中很难做到,因为没有明确的模式,我在 python 中尝试了一些东西,但没有成功(因为我还在学习 python)。

问题陈述:

我的 sql 查询输出是 excel 或文本文件(取决于我发布它的方式,但可以同时进行)。我有一个字段(excel 或文本文件中的第四列),其中包含一个或多个拒绝原因(参见下面的示例),用逗号分隔。同时,在错误中使用逗号(有时)。

未做任何修改的字段示例

INVOICE_CREATION_Failed[无效地址信息:公司名称,有限公司:BlueBerry Street 10+City++09301+SK|SK000001111|BLD 在第 1 行,发票上的公司 ID 与系统中为代码注册的公司 ID 不匹配: [AL12345678901]|ABC1D|DL0000001 在第 2 行,采购订单不正确:VTB2R|ADLAVA9 在第 1 行 ]

期望的输出:

无效的地址信息;发票上的公司 ID 与系统中为代码注册的公司 ID 不匹配;错误的采购订单

Python 代码:

import pandas

excel_data_df = pandas.read_excel(''rejections.xlsx'')

# print whole sheet data
print(excel_data_df[''Invoice_Issues''].tolist())

excel_data_df[''Invoice_Issues''].split(":",1)

输出

INVOICE_CREATION_Failed[Invalid Address information:

我尝试过拆分字符串,但无法正常工作。它删除冒号后的所有内容,这是可以接受的,因为它是这样编码的,但是,我需要修剪不必要的数据字符串并只保留每行所需的输出。 我将非常感谢任何关于如何修剪输出的代码建议,我只会从该字符串中提取所需的内容 - 如果子字符串可用。

在 excel 中,我通常会使用错误列表以及带有 FIND 和 MATCH 的嵌套 IF 函数。但我不知道如何在 Python 中做到这一点...

非常感谢,

格雷格

解决方法

这不是最快的方法,但在 Python 中,速度很少是最重要的。

在这里,我们手动创建错误字典以及您希望它们映射到的内容,然后我们遍历 Invoice_Issues 中的值,并使用字典查看该键是否存在。

import pandas

# create a standard dataframe with some errors
excel_data_df = pandas.DataFrame({
    ''Invoice_Issues'': [
        ''INVOICE_CREATION_FAILED[Invalid Address information: Company Name,Limited: Blueberry Street 10+City++09301+SK|SK000001111|BLD at line 1,Company Id on the Invoice does not match with the Company Id registered for the Code in System: [AL12345678901]|ABC1D|DL0000001 at line 2,Incorrect Purchase order: VTB2R|ADLAVA9 at line 1 ]'']
})

# build a dictionary 
# (just like "words" to their "meanings",this maps 
#  "error keys" to their "error descriptions".
errors_dictionary = {
    ''E01'': ''Invalid Address information'',''E02'': ''Incorrect Purchase order'',''E03'': ''Invalid VAT ID'',# ....
    ''E39'': ''No tax line available''
}


def extract_errors(invoice_issue):
    # using the entry in the Invoice_Issues column,# then loop over the dictionary to see if this error is in there.
    # If so,add it to the list_of_errors.
    list_of_errors = []
    for error_number,error_description in errors_dictionary.items():
        if error_description in invoice_issue:
            list_of_errors.append(error_description)
    return '';''.join(list_of_errors)
    

# print whole sheet data
print(excel_data_df[''Invoice_Issues''].tolist())


# for every row in the Invoice_Isses column,run the extract_errors function,and store the value in the ''Errors'' column.
excel_data_df[''Errors''] = excel_data_df[''Invoice_Issues''].apply(extract_errors)

# display the dataframe with the extracted errors
print(excel_data_df.to_string())
excel_data_df.to_excel(''extracted_errors.xlsx)

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”

如何解决/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”

我正在 mac OS X 上使用 ESP8266Flash.app 更新 ESP8266 固件。 但是当我开始刷固件时出现以下错误:

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can''t open file ''esptool.py'': [Errno 1] Operation not permitted."

我该如何解决这个问题?

CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取

CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取

如何解决CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取

我有一个看起来像这样的 CMake 脚本:

  1. find_program(PYTHON_COMMAND NAMES python3 python)

问题是它检测到安装在 Cygwin 安装中的 python。 输出总是:

  1. -- PYTHON_PATH:C:/cygwin64/bin/python3

我希望它取自:

  1. c:\\python36-64\\python

在windows PATH变量中,Cygwin bin在路径的最后一个,windows安装在第一个 但它只检测到 Cygwin python,
怎么改?

Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod

Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod

It's important to understand the Python execution model and precisely when function deFinitions and other important events occur when a module is imported or executed. Here, we show execution of our Python module as it's imported in a graphical debugging environment. We step through the top‑level statements in the module. What's important to realize here is that the def used for the fetch_words function isn't merely a declaration. It's actually a statement, which when executed in sequence with the other top‑level model scope code, causes the code within the function to be bound to the name of the function. When modules are imported or run, all of the top‑level statements are run, and this is the means by which the function within the module namespace are defined. We are sometimes asked about the difference between Python modules, Python scripts, and Python programs. Any .py file constitutes a Python module. But as we've seen, modules can be written for convenient import, convenient execution, or using the if dunder name = dunder main idiom, both. We strongly recommend making even simple scripts importable since it eases development and testing so much if you can access your code from within the REPL. Likewise, even modules, which are only ever meant to be imported in production settings, benefit from having executable test code. For this reason, nearly all modules we create have this form of defining one or more importable functions with a postscript to facilitate execution. Whether you consider a module to be a Python script or Python program is a matter of context and usage. It's certainly wrong to consider Python to be merely a scripting tool, in the vein of Windows batch files or UNIX Shell scripts, as many large and complex applications are built exclusively with python.

 

  • def不仅仅是一个declaration声明,更是一条statement语句。它将其中的python代码于函数名绑定在一起
  • 一个py文件就是一个模块,这个模块包含类或函数。你写python,要尽量将代码包装成函数和类,方便各种import
  • 一个py文件也可看作是一个脚本,在系统命令行中运行
  • python不仅仅是脚本语言,很多大型程序都是用python构建的

Error: Can‘t find Python executable “python“, you can set the PYTHON env variable

Error: Can‘t find Python executable “python“, you can set the PYTHON env variable

在启动vue项目的时候,安装node.js组件node-sass过程中报错了,错误提示如下
Error: Can’t find Python executable “python”, you can set the PYTHON env variable

由错误提示可知:Node.js 在安装模块组件node-sass的时候,node.js缺少Visual Studio2015 Build Tools相关的组件和python的环境,如果安装了vs2015组件的小伙伴们就不用安装Visual Studio2015 Build Tools相应的组件,只用安装python2.7即可解决缺少的python组件的问题。

欲安装python2.7,请至python官网:www.python.org 下载,然后配置好python的环境变量即可。

不过博主我并不推荐上述的解决方案,因为对于程序员来说,效率第一,上述的问题一个命令就可以轻松解决你所遇到的麻烦,前面说了那么多,无非就是想告诉在看本篇博客的同仁们放下浮躁的心,遇到问题首先不是急着去解决问题,而是分析为什么会这样,然后才能水到聚成的去找到解决问题的方法。

运行下面这个命令即可解决你们遇到的Error问题

npm install --global --production windows-build-tools

:上面讲述了一堆就是为了讲述此命令是干嘛的,上面已经描述很详细了,就不再赘述了,该操作与上述的一堆操作无异,效果却是一样的。

然后运气不好的小伙伴可能接着会遇到一个坑,那就是执行了:npm install --global --production windows-build-tools这个命令的人细心点会发现执行到一半就卡住了,这个卡住了没有红字重点提示,而且下方还有英文在等待中,粗心的小伙伴可能以为是命令执行完了,组件安装好了,其实不然,我这边已经解决了,就无法复现了,具体点就是中文的提示,提示我们由于有类似组件在运行或者下载导致无法继续下载安装组件了。稳妥点的解决办法是,将电脑重启,将底层正在运行的模块干掉,待电脑重启后再执行npm install --global --production windows-build-tools这条命令即可,博主我就是这样解决的,稳稳的幸福就会浮现在你面前如下图所示,你的可能和我不一样,因为我已经跑成功过一次了,没有你的那么多细节的log打印。
在这里插入图片描述

然后就是在你的项目下shift+鼠标右击你的项目运行npm run dev即可启动vue项目了。

我们今天的关于Python:从字符串中提取唯一的句子并将它们放在用 ;python在一串字符中提取指定的字符的分享就到这里,谢谢您的阅读,如果想了解更多关于/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python:无法打开文件“esptool.py”、CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取、Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod、Error: Can‘t find Python executable “python“, you can set the PYTHON env variable的相关信息,可以在本站进行搜索。

本文标签: