0

I'm working with a DataFrame and after doing some changes in the DataFrame(in fact drop some rows).Then I select a column to make a list of lists and then try to work on it. So the code is

st_or = list (Nsetg['Aip'][k:k+2] for k in range (0, len(Nsetg['Aip'])-1, 1)) # Nsetg is the DataFrame modified,so I select the column 'Aip'

But in the list I have to drop some duplicate elements, I have some code to do this and the first thing is sort the list, which give me an exception :

st_or.sort()
"Can only compare identically-labeled Series objects"

I think the problem is because the index of the elements in the list, I'm quite sure, but if I try to print the list I get something like this : `

print st_or
[0    0
1    1
Name: Aip, dtype: int64, 1    1
2    2
Name: Aip, dtype: int64, 2    2
3    4
Name: Aip, dtype: int64, 3    4
4    6
Name: Aip, dtype: int64]

What I was expecting to get after print the list is:

[[0,1],[1,2],[2,4],[4,6], ...,]

How can I get a better result ?

1
  • 1
    Please provide a small reproducible sample data set and your desired data set Commented Nov 28, 2017 at 16:56

1 Answer 1

1

Adding .values.tolist()

st_or = list (Nsetg['Aip'].iloc[k:k+2].values.tolist()
 for k in range (0, len(Nsetg['Aip'])-1, 1)) 
Sign up to request clarification or add additional context in comments.

1 Comment

@Soichiru Yw~ :-) happy coding

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.