I have a csv file mentioned as below screen shot ...
and i want to convert the whole file in the below format in python.
I have a csv file mentioned as below screen shot ...
and i want to convert the whole file in the below format in python.
You can try this after reading your CSV file correct file path.
import pandas as pd
df = pd.read_csv("path/to/file", names=["Sentence", "Value"])
result = [(row["Sentence"], row["Value"]) for index, row in df.iterrows()]
print(result)
It's a single line using apply()
method of dataframe
df.apply(lambda x: x.tolist(), axis=1)
OR
df.values.tolist()
will also work