pandas : Import snippet
TC_ID | TC_NAME | QUERY1 | QUERY2 | CONDITION | BASICTEST(QUERY1/QUERY2) |
TC0001 | TC_NAME1 | Select col1 from table1 | Select col1 from table2 | 1 | 11 |
TC0002 | TC_NAME2 | Select col1 from table2 | Select col1 from table3 | 2 | 12 |
TC0003 | TC_NAME3 | Select col1 from table3 | Select col1 from table4 | 3 | 13 |
TC0004 | TC_NAME4 | Select col1 from table4 | Select col1 from table5 | 4 | 14 |
TC0005 | TC_NAME5 | Select col1 from table5 | Select col1 from table6 | 5 | 15 |
TC0006 | TC_NAME6 | Select col1 from table6 | Select col1 from table7 | 6 | 16 |
To select row and Traverse cells from selected rows
import pandas as pd
df=pd.read_csv("/home/deepak/PycharmProjects/csv_test/test_cases.csv")
O_row=(df[df["TC_ID"]=="TC0006"])
print(O_row["TC_NAME"].values[0])
Output:
TC_NAME6
import pandas as pd
df=pd.read_csv("/home/deepak/PycharmProjects/csv_test/test_cases.csv")
O_row=(df[df["TC_ID"]=="TC0006"])
print(O_row["TC_NAME"].values[0])
Output:
TC_NAME6
To convert CSV to list of dictionaries:
(Using Pandas)
import pandas as pd
import csv
df = pd.read_csv(sPath)
list_of_data = df.to_dict(orient='records')#dropna().to_dict(orient='recorddel df
return list_of_data
(Using CSV)
import pandas as pd
import csv
with open(sPath, "r") as f:
reader = csv.DictReader(f)
list_dict = list(reader)
return list_dict
No comments:
Post a Comment