0

Good day, I am working with the pandas. I have .xyz data. Wanted to create pandas from it.

point_cloud = pd.read_csv("Turning.xyz", delimiter=" ")

point_cloud = point_cloud.iloc[:,1:]
print(point_cloud.values[:5])

I read with this way. It worked and following is the output.

[[ 5.29851664  2.17091972 -1.5342793 ]
 [ 5.33154001  2.09907462 -1.53531458]
 [ 5.33154001  2.09907462 -1.53531458]
 [ 5.36755701  2.02716027 -1.53738513]
 [ 5.37840056  2.03125554 -1.54049096]]

Now I want that 1 col would be "X" in the dataframe, next one "Y", and next one is "Z". So I did it like that:

point_cloud = pd.DataFrame(point_cloud.values[:5000], columns={"X","Y","Z"})

I took only 5000 for my case, as there are lots of points in it. However it does not created the dataset with normal order X Y Z but it created with Y Z X:

          Y         Z         X
0  5.298517  2.170920 -1.534279
1  5.331540  2.099075 -1.535315
2  5.331540  2.099075 -1.535315
3  5.367557  2.027160 -1.537385
4  5.378401  2.031256 -1.540491

It is the 1st time I saw something like that. What could be the reason and how to solve it?

1 Answer 1

1

Don't use a set because it's unordered collection.

Replace:

columns={"X","Y","Z"}

by:

columns=["X","Y","Z"]
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thanks. Did not was very attentive. Thanks again

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.