[pandas] When the indexing is not good?

Asked 2 years ago, Updated 2 years ago, 67 views

I have data. It's in the form of a pandas data frame. I'm going to bring it in and do something, but it's not indexing well. I can't get all the original data.

For example,

df = np.random.randint(1, 15, size=[3,5])
df = pd.DataFrame(df)
df.columns = ['a', 'b', 'c', 'd', 'e']

If you have a data frame
The following calls are made:

df.a[0]

You need to get only one element value in column a, but you need to get everything from line 1 to the end. When printed out, the index of row is all marked as 0.
When df.a[3] is called, the index of row is all written as 3.
They're calling me from line 3 to the end.

I'm not used to using Pandas now. I don't know what's wrong. When does this happen? I ask for your help me.

pandas dataframe series

2022-09-21 19:59

1 Answers

Okay, I got it. There can be something with the same index of row It's because there are several indexes that are zero.


2022-09-21 19:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.