How do I open a binary matrix and convert it into a 2D array or a dataframe?

S. Quon

I have a binary matrix in a txt file that looks as follows:

0011011000
1011011000
0011011000
0011011010
1011011000
1011011000
0011011000
1011011000
0100100101
1011011000

I want to make this into a 2D array or a dataframe where there is one number per column and the rows are as shown. I've tried using numpy and pandas, but the output has only one column that contains the whole number. I want to be able to call an entire column as a number.

One of the codes I've tried is:

with open("a1data1.txt") as myfile:
    dat1=myfile.read().split('\n')
dat1=pd.DataFrame(dat1)
BEN_YO

After you read your txt, you can using following code fix it

pd.DataFrame(df[0].apply(list).values.tolist())
Out[846]: 
   0  1  2  3  4  5  6  7  8  9
0  0  0  1  1  0  1  1  0  0  0
1  1  0  1  1  0  1  1  0  0  0
2  0  0  1  1  0  1  1  0  0  0
3  0  0  1  1  0  1  1  0  1  0
4  1  0  1  1  0  1  1  0  0  0
5  1  0  1  1  0  1  1  0  0  0
6  0  0  1  1  0  1  1  0  0  0
7  1  0  1  1  0  1  1  0  0  0
8  0  1  0  0  1  0  0  1  0  1
9  1  0  1  1  0  1  1  0  0  0

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can i convert 2d array into matrix in C?

How do I convert my 2D numpy array to a pandas dataframe with given categories?

how do you convert a dataframe into 2d numpy array

How to convert 2d numpy array into binary indicator matrix for max value

Convert a binary image to 2D array or Matrix in Python?

How do I convert an array of integers to binary?

How do i convert a Set into 2D array in java?

How do I convert a String to an 2D Array of ints?

Convert a 2 column dataframe into a symmetric binary matrix

How to convert .mat binary format to 2D numpy array?

How do I read from/write to a binary file in 2D Array form?

How do I convert a 2D transformation matrix (for homogeneous coordinates) into 3D in the z=0 plane?

How do I update a 2d array to convert grades to their GPA values?

How do I load every image in a file and convert them to 2D array then export it to a new folder?

How do I convert this C++ 2D array code into Python?

how to convert one column in dataframe into a 2D array in python

How do I rotate 2D matrix properly?

I want to convert a label numpy array into binary matrix?

How do I convert a numpy array into a pandas dataframe?

how do i convert a numpy array to pandas dataframe

How do I efficiently convert pandas dataframe to image array?

How do I convert a Python DataFrame into a NumPy array

How can I convert an 2D int array into a 2D String array with Streams?

How can I convert a 2d Number array into a 2d String array?

Convert 2D binary matrix to black/white image in java

How do I change the dimension of an image from 3D matrix to 2D matrix in python?

How do I multiply a 3D matrix and 2D matrix using numpy in Python?

How can I convert (binary) integer into array?

How to convert a OpenCV 2D matrix into a 1D array in C++?