#๐ axis=0 or 1? pandas
29 messages ยท Page 1 of 1 (latest)
@wide cosmos
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
From what ive read, axis=1 means columns, and axis=0 means rows
right
the above screenshot however shows that applying a sum function to rows returns the summation of the columns
hows that?
axis=0 means apply along axis 0, so "vertically". So it collapses each column, and returns a Series with an entry for each column.
Whereas axis=1 means apply along axis 1, so horizontally - collapsing each row into an entry, and returning a series with the same index as the dataframe.
i mean isnt the pandas convention that axis=1 refers to columns
so instead axis=1 should refer to "applying along a column"
its not a mathematical notation
its a library convention right
Depends on what you mean. As the first index (of iloc, say) changes, you move vertically - that's what I mean by axis 0 being vertical. But df.iloc[0] is the same as df.iloc[0,:] - the first row of a dataframe.
Whereas as the second index changes, you move horizontally. So if you fix that index (while letting the first one change), you get a single column of a dataframe.
One way you could remember this is that if you do z = np.sum(arr, axis=0), that means z[i] is the sum of arr[0, i] + arr[1,i] + arr[2, i] + ... - so the zeroth axis is the one getting iterated over to do the sum.
im still not fluent in numpy
but i may or may not have understood
i think i gotta look at numpy arrays more lol
im curious, what do you do?
numerical physics mostly, if I understand the question correctly.
sure
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.