1
import pandas as pd

rawDF = pd.read_csv('D:\Project\python\Grade\GradeDataRaw.csv',names=['GradeCol'])

filteredDF = rawDF[rawDF['GradeCol'].str.contains('EVCS:|BVCS:|LOW POINT STA')]
print(filteredDF)

filename = 'GradeOut.csv'

filteredDF.to_csv(filename,index=False, encoding='utf-8')

Output in CSV file is

GradeCol

EVCS: 210+080.907

BVCS: 210+080.907

LOW POINT STA =208+108.133\PLOW POINT ELEV = 66.849\PPVI STA = 209+126.315\PPVI ELEV = 66.762\PA.D = 1.413%\PK

LOW POINT STA =208+108.133\PLOW POINT ELEV = 66.849\PPVI STA = 209+126.000\PPVI ELEV = 66.762\PA.D = 1.413%\PK

Would like to have only "PPVI STA = 209+126.315" in data frame row where there is this string available, other rows with EVCS & BVCS to remain intact, numerical part can vary in every row. With the extract method getting NaN values in the rows where the is no match , that is not the intention.

4
  • What is your desired output? do you want to order all the rows? Commented Jul 15, 2017 at 15:47
  • "info \GPK HEK = 209+126.315\info ends here" - is it the whole string/row or just one column in the row? Commented Jul 15, 2017 at 15:52
  • hello guys , hope the above edit with more information helps to clarify the expected output. Commented Jul 15, 2017 at 20:16
  • Welcome to the site: you may want to read help center, How to Ask and minimal reproducible example, and re-word your question accordingly. Commented Jul 17, 2017 at 14:35

2 Answers 2

1

IIUC:

Sample DF:

In [99]: df
Out[99]:
                                                 txt
0         info \GPK HEK = 209+126.315\info ends here
1  blah-blah-blah GPK HEK = 1 + 2.33333end of string

Solution:

In [100]: df['txt'].str.extract(r'(GPK HEK\s*=\s*\d+\s*\+\s*\d+\.\d+)', expand=False)
Out[100]:
0    GPK HEK = 209+126.315
1    GPK HEK = 1 + 2.33333
Name: txt, dtype: object
Sign up to request clarification or add additional context in comments.

1 Comment

hello MaxU, kindly have a look at the new edited information.
0

This should do the job.

def parse(string):
    start = string.find('\\') + 1
    end   = string.find('.')

    while string[end] != '\\':
        end += 1

    return string[start : end]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.