Jan-23-2020, 08:35 AM
(This post was last modified: Jan-23-2020, 08:35 AM by sandeep_ganga.)
Try this to see if that helps,
Sandeep
GANGA SANDEEP KUMAR
import pandas as pd df=pd.read_csv("ab.csv",header=0, names=['roadno']) print(df) data=[] for i in df['roadno']: if i[:1].lower()=="h" or i[:1].lower()=="m": #if i[:1].lower() in ('h','m'): data.append("MAIN road") else: data.append("other road") print(data) df["new column"]=data print(df)
Output:python test2.py
roadno
0 H001
1 H0002
2 M002
3 M03050
4 A001
5 B002
6 C002
7 F002
8 5001
9 8002
['MAIN road', 'MAIN road', 'MAIN road', 'MAIN road', 'other road', 'other road', 'other road', 'other road', 'other road', 'other road']
roadno new column
0 H001 MAIN road
1 H0002 MAIN road
2 M002 MAIN road
3 M03050 MAIN road
4 A001 other road
5 B002 other road
6 C002 other road
7 F002 other road
8 5001 other road
9 8002 other road
Best Regards,Sandeep
GANGA SANDEEP KUMAR