#๐ Row equivalent of .columns in pandas?
24 messages ยท Page 1 of 1 (latest)
@stray spade
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.
technically .index but what exactly are you trying to do?
if you are trying to iterate over the rows like you would over a python list, don't (there are methods for that but it is a LOT slower than using pandas methods)
I'm not trying to iterate over rows, I was trying to save the rows to a different variable but I actually do not think thats what I need to do lol.. I'm working on a data classification assignment so I don't think the rowname will help with anything
Is there a way to return column name?
what do you mean by "save the rows to a different variable"? what type would that object be?
Yeah the logic there wasn't really sound, I don't even know if that thought is possible/makes sense
strictly speaking that would be df.columns[i], or series.name
what are you even trying to do in first place though?
not in code, not your attempted solution, just the problem you are trying to solve
I'm sorry I know its confusing, part of me doesn't exactly know what to do. I was attempting to breakup the dataframe into two different parts I guess
you can do something like
df_1 = df.loc[['a', 'b', 'c']]
df_2 = df.loc[['d', 'e', 'f']]
where those letters are indices for rows
but only if there's a reason why having some rows in different dataframes is better than just having one.
Okay, that makes sense. I think I actually need to split it by columns, not rows. Is there a way to index to save just the last column?
df[-1]```
you would do df.iloc[:, -1] for that
Ok, how would I save everything but the last column then?
Makes sense. I wasn't familiar with the syntax of using ':'
I think that solved it. thank you
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.
๐ Row equivalent of .columns in pandas?