I am new to python. I have a text file as 'asv.txt' having the following content:
[['10', '50', '', ' Ind ', '', ''], ['40', '30', '', ' Ind ', 'Mum', ''], ['50', '10', '', ' Cd ', '', '']]
How do I read it as a csv or as a dataframe.
I am new to python. I have a text file as 'asv.txt' having the following content:
[['10', '50', '', ' Ind ', '', ''], ['40', '30', '', ' Ind ', 'Mum', ''], ['50', '10', '', ' Cd ', '', '']]
How do I read it as a csv or as a dataframe.
# Read file (or just copy text)
with open('asv.txt') as f:
data = f.read()
# Convert str to list with ast
import ast
data = ast.literal_eval(data)
## Load dataframe using the "data" argument, which can accept a list and treats it as rows
df = pd.DataFrame(data=data)
Or much simpler for this specific case:
df = pd.DataFrame(data=[['10', '50', '', ' Ind ', '', ''], ['40', '30', '', ' Ind ', 'Mum', ''], ['50', '10', '', ' Cd ', '', '']])