Documentation request: Iterating a DataFrame
See original GitHub issueI’d be happy to add this once I could figure it out. I’ve been able to load my tabular text files, store them as h5ad, then load them back again. I cannot see how to iterate over rows, then columns so that I can access all values of the dataframe with an awareness of which row/column each belongs to.
My wishful code example:
adata = sc.read_h5ad(filename)
selected = adata[:, adata.var_names.isin({'AAR2', 'ECT2'})]
## this line spews information on the columns like:
# Empty DataFrameView
# Columns: []
# Index: [Cancer--Cell_1, Cancer--Cell_10, Cancer--Cell_100, Cancer--Cell_1000, Cancer--Cell_1001
#print(selected.obs)
## this line gives the row information:
# Empty DataFrameView
# Columns: []
#Index: [AAR2, ECT2]
#print(selected.var)
# Nothing happens here at all
#for i, row in selected.obs.iteritems():
# print(i, row)
for gene_name, row in selected.var.iterrows():
# this prints like: Series([], Name: AAR2, dtype: float64)
print(row)
# Nothing happens here
for cell_name, val in row.iteritems():
print("{0}\t{1}\t{2}".format(gene_name, cell_name, val))
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Documentation request: Iterating a DataFrame #70 - GitHub
I've been able to load my tabular text files, store them as h5ad, then load them back again. I cannot see how to...
Read more >Different ways to iterate over rows in Pandas Dataframe
In this article, we will cover how to iterate over rows in a DataFrame in Pandas. How to iterate over rows in a...
Read more >How to Iterate Over Rows in a Pandas DataFrame
pandas documentation. In today's article, we will discuss how to avoid iterating through DataFrames in pandas. We'll also go through a ...
Read more >pandas: Iterate DataFrame with "for" loop - nkmk note
If pandas.DataFrame is iterated by for loop as it is, column names are returned. You can iterate over columns and rows of pandas....
Read more >Pandas Iterate Over Rows with Examples
But it is not recommended to manually loop over the rows as it degrades the performance of the application when used on large...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
now you missed the sweet stackoverflow reputation, alex 😈
Thank you! 😄