0

I have a data frame, each rows has a string like (without space between the values) [1 2 3 4 5]. I want to get the rows as an array. Here is part of my data frame

enter image description here

Here is an example of my data frame:

import pandas as pd 

df = pd.DataFrame()
df['a'] = [1, 2, 3]
df['b'] = [str([1 2]), str([2 3 4 5 6 7]), str([2 3 4 5])]

The output which I want is, for example row with index 1 is:

row_2 = np.array([2, 3, 4, 5, 6, 7])

could you please help me with that? Thanks.

1 Answer 1

1

You can store everything this way.

import pandas as pd 
df = pd.DataFrame()
df['a'] = [1, 2, 3]
df['b'] = ["12", "234567", "2345"]

arr=[]
for i in df['b']:
  arr.append([int(j) for j in i])

print(arr)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.