Skip to content

Add direct pandas/CSV export methods to Spin and SpinCollection #35

Description

@carlosbornes

read_nmr() returns a SpinCollection, but there is currently no direct way to convert a loaded object into a pandas/polars DataFrame. Tabular export is only available through spinplots.utils.nmr_df, which requires working from file paths rather than from already-loaded objects.

One could make it easier and more consistent by implementing a to_pandas() to both Spin and SpinCollection.

Example

from spinplots.io import read_nmr

collection = read_nmr([
    "data/1D/glycine/pdata/1",
    "data/1D/alanine/pdata/1",
], tags=["Glycine", "Alanine"])

df = collection.to_pandas()
df.to_csv("spectra.csv", index=False)

Behaviour

  • Spin.to_pandas() returns a DataFrame for a single spectrum
  • SpinCollection.to_pandas() returns a concatenated DataFrame with a tag column
  • nmr_df() can remain for backward compatibility, but internally both paths could share the same dataframe-building logic

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions