I would like to create a pandas dataframe out of a list variable.
With pd.DataFrame() I am not able to declare delimiter which leads to just one column per list entry.
If I use pd.read_csv() instead, I of course receive the following error
ValueError: Invalid file path or buffer object type: <class 'list'>
If there a way to use pd.read_csv() with my list and not first save the list to a csv and read the csv file in a second step?
I also tried pd.read_table() which also need a file or buffer object.
Example data (seperated by tab stops):
Col1 Col2 Col3
12 Info1 34.1
15 Info4 674.1
test = ["Col1\tCol2\tCol3", "12\tInfo1\t34.1","15\tInfo4\t674.1"]
Current workaround:
with open(f'{filepath}tmp.csv', 'w', encoding='UTF8') as f:
[f.write(line + "\n") for line in consolidated_file]
df = pd.read_csv(f'{filepath}tmp.csv', sep='\t', index_col=1 )
[['Col1', 'Col2', 'Col3'], ['12', 'Info1', '34.1'], ['15', 'Info4', '674.1']]and then useDataFrame- like in answer. OR if you would convert it to single string (using'\n')as line separator then you could useread_csvwithio.BytesIOorio.StringIOto create file in memory.io.BytesIOis popular if you get file (data, image, audio) from network and you want to use it without saving on disk.