question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation request: Iterating a DataFrame

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
flying-sheepcommented, Jan 30, 2018

now you missed the sweet stackoverflow reputation, alex 😈

0reactions
falexwolfcommented, Jan 30, 2018

Thank you! 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found