I have file.txt:
1,2,3,4;5,6
7,8,2,1;
2,9;1
I need to import this data to DataFrame in to columns separated by ";", so I do:
import pandas as pd
data = pd.read_csv('file.txt', sep = ';', names = ['Col1', 'Col2'])
data = data.fillna('0')
As a result I get:
Col1 Col2
1,2,3,4 5,6
7,8,2,1 0
2,9 1
The rows have string format. But I need integers or lists of integers in every row, like:
Col1 Col2
[1,2,3,4] [5,6]
[7,8,2,1] [0]
[2,9] [1]
or just numbers, not strings, no lists. How to do that?
To get a list of integers in each cell you could use something like this: