提取包含关键字

时间:2018-12-12 13:17:20

标签: python

已解决问题,每当col1具有关键字时,我都希望在col2中提取时间戳记

keywords = [“我可以为您提供帮助”,“我可以为您提供帮助”,“我可以为您提供帮助和帮助”,“我很乐意为您提供帮助”,“让我在此方面为您提供帮助”,“为您提供更好的帮助”]

给出excel数据,

    col1                                                                                                                            
1.agent enters(as arrin)
2.
3.I'll be happy to assist you. Give me a moment to review your request.
4.I see that the light in your Modem is Blinking Red. Am I right ?
5.Thank you for the detailed information.
6.Please do not worry.
7.Don't worry johny. I can help you with that.
8.Let me connect this chat to the concern team to help you out with this, 
  Please stay connected.

   col2
1. 2018-10-14 21:16:58
2. 2018-10-14 21:17:00
3. 2018-10-14 21:17:40
4. 2018-10-14 21:18:25
5. 2018-10-14 21:19:39
6. 2018-10-14 21:19:43
7. 2018-10-14 21:21:04
8. 2018-10-14 21:22:00

例如第7行中存在关键字之一,因此要提取的col2中的相应时间戳记

所需的输出应如下所示

[出]:2018-10-14 21:21:04

预先感谢

2 个答案:

答案 0 :(得分:1)

尝试一下:

keywords = [
            "i can help you with that",
            "i can surely help you with that",
            "i can check and help you with that",
            "i will be more than happy to help you",
            "let me assist you on this",
            "to assist you better"
]

for phrase in keywords:
    for row in col1:
        if phrase in row.lower():
            return row

所以这是在查看Excel工作表的列...

          col1
1 Hello and welcome
2 There's a lot to see here
3 Sorry, no can do
4 I can help you with that if you'd like

并逐一进行。如果这些行之一包含您的关键字短语...

>I can help you with that< if you'd like

它将返回整行。您可以打印而不是退货或对该行进行任何其他操作。 .lower()方法是因为我们的关键字以小写形式存储,因此应将它们与该行的小写版本进行比较。如果匹配,我们可以返回原来的行。当然,我假设您已经设法将您的数据导入col1中,就像某种列表一样……让我知道您是否需要帮助。

答案 1 :(得分:1)

我认为这会有所帮助

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cam : MonoBehaviour
{
    [Header("Locations where camera will update its position step by step")]
    public Transform handleview;
    public Transform needle1view;
    public Transform wallview;
    public Transform handletwoview;
    public Transform needle2view;
    public Transform switchview;
    public Transform lastswitchview;

    public GameObject Animatebtn;
    Animator animatebtnanim;

    [Header("UI Buttons")]
    public GameObject inspectionbtn;
    public GameObject animatebtn;
    public GameObject step2btn;
    public GameObject step3btn;
    public GameObject step4btn;
    public GameObject step5btn;
    public GameObject step6btn;
    public GameObject step7btn;

    [Header("Inspection Views")]
    public Transform startview;
    public Transform handle1view;
    public Transform motorview;
    public Transform handle2view;

    [Header("Move Boolean")]
    public bool move = false;

    [Header("Speed At Which Cam Moves")]
    public float speed;

    [Header("Current View/position Of Camera")]
    Transform currentVIEW;

    [Header("Current Angel Of Camera")]
    Vector3 currentangel;

    [Header("FieldofView of Camera ")]
    public float camFieldOFview = 24f;

    public int track = 0;

    // Use this for initialization
    void Start()
    {
        Camera.main.fieldOfView = camFieldOFview;
        animatebtnanim = Animatebtn.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (move)
        {
            //float step = speed * Time.deltaTime;
            //transform.position = Vector3.MoveTowards(transform.position, currentVIEW.position, step);
            transform.position = Vector3.Lerp(transform.position, currentVIEW.position, Time.deltaTime * speed);
            currentangel = new Vector3(Mathf.LerpAngle(transform.rotation.eulerAngles.x, currentVIEW.transform.rotation.eulerAngles.x, Time.deltaTime * speed),
                Mathf.LerpAngle(transform.rotation.eulerAngles.y, currentVIEW.transform.rotation.eulerAngles.y, Time.deltaTime * speed),
                Mathf.LerpAngle(transform.rotation.eulerAngles.z, currentVIEW.transform.rotation.eulerAngles.z, Time.deltaTime * speed));

            transform.eulerAngles = currentangel;
        }

        //if (Input.GetKey(KeyCode.RightArrow))
        //{
        //    if (track == 7)
        //        track = 1;
        //    if (track == 1)
        //    {
        //        moveTOstartVIEW();
        //        move = true;
        //    }
        //    else if (track == 2)
        //    {
        //        moveTOhandleONEview();
        //        move = true;
        //    }
        //    track += 1;

        //}

    }
    // this function will lerp camera to startview location
    public void moveTOstartVIEW()
    {
        currentVIEW = startview;
        move = true;
    }

    public void moveTOhandleONEview()
    {
        currentVIEW = handle1view;
        move = true;
        animatebtnanim.SetBool("start", true);
        animatebtnanim.SetBool("move", false);
    }

    public void moveTOmotorview()
    {
        currentVIEW = motorview;

        move = true;
    }


    public void moveTOhandleTWOview()
    {
        currentVIEW = handle2view;
        move = true;
    }

    public void Handleview()
    {
        currentVIEW = handleview;
        inspectionbtn.SetActive(false);
        animatebtn.SetActive(false);
        move = true;
    }

    public void Needleoneview()
    {
        currentVIEW = needle1view;
        step2btn.SetActive(false);
        move = true;
    }

    public void Wallview()
    {
        currentVIEW = wallview;
        move = true;
        step3btn.SetActive(false);
    }

    public void Handletwoview()
    {
        currentVIEW = handletwoview;
        move = true;
        step4btn.SetActive(false);
    }

    public void Needletwoview()
    {
        currentVIEW = needle2view;
        move = true;
        step5btn.SetActive(false);
    }

    public void Switchview()
    {
        currentVIEW = switchview;
        move = true;
        step6btn.SetActive(false);
    }

    public void lastSwitchview()
    {
        currentVIEW = lastswitchview;
        move = true;
        step7btn.SetActive(false);
    }
}