pandas-dataframe-manipulation-ms-columns
Summary
Prepare and structure mass spectrometry data within Pandas DataFrames by organizing and selecting columns for m/z, retention time, and intensity dimensions required by pyOpenMS-Viz plotting methods. This skill ensures data is in the correct format and column names are compatible with the visualization backend.
When to use
When you have raw mass spectrometry data (from mzML, Bruker .d, or CSV format) loaded into a Pandas DataFrame and need to ensure it has the correct column structure (m/z, retention time, intensity) before invoking pyOpenMS-Viz plotting functions like .plot(kind='spectrum'), .plot(kind='peakmap'), or .plot(kind='chromatogram').
When NOT to use
- Data is already in a specialized mass spectrometry object format (e.g., pyOpenMS MSSpectrum, MSChromatogram) that does not need DataFrame conversion
- Column structure and naming are already validated and match pyOpenMS-Viz expectations
- Input is binary or proprietary mass spectrometry data that requires vendor-specific parsers before any DataFrame creation
Inputs
- Pandas DataFrame with mass spectrometry data (loaded from mzML, Bruker .d, CSV, or similar format)
- Column names and data types present in the DataFrame
- Target plot type (spectrum, chromatogram, peakmap, mobilogram)
Outputs
- Prepared Pandas DataFrame with correctly named and typed columns (m/z, retention time, intensity)
- DataFrame ready for input to pyOpenMS-Viz .plot() method
How to apply
Load mass spectrometry data into a Pandas DataFrame using appropriate readers (PyOpenMS, pymzML, pyteomics for mzML, or alphatims for Bruker .d format), ensuring the resulting DataFrame contains columns for m/z (mass-to-charge ratio), retention time (rt), and intensity values. Inspect and rename columns as needed to match the expected names used by pyOpenMS-Viz (typically 'x', 'y', 'z' or domain-specific names like 'm/z', 'rt', 'intensity'). Use the 'versatile column selection' feature documented in pyOpenMS-Viz to map your DataFrame columns to the required dimensions for your chosen plot type. Verify column data types are numeric (float or int) before passing the DataFrame to the plotting method. This standardization enables seamless backend switching and ensures consistent API behavior across matplotlib, Bokeh, and Plotly backends.
Related tools
- Pandas (DataFrame data structure and column manipulation for organizing m/z, retention time, and intensity columns)
- PyOpenMS (Loading and parsing mass spectrometry data from mzML and native OpenMS formats into Pandas-compatible structures)
- pymzML (Alternative parser for mzML mass spectrometry files into DataFrame-ready format)
- pyteomics (Alternative parser for mzML mass spectrometry files into DataFrame-ready format)
- alphatims (Parser for Bruker .d format mass spectrometry files into DataFrame-ready format)
- pyOpenMS-Viz (Visualization library that consumes prepared DataFrames with correctly named m/z, retention time, and intensity columns via the .plot() method) — https://github.com/OpenMS/pyopenms_viz
Examples
ms_data = pd.read_csv('path/to/ms_data.csv')
ms_data.plot(x='m/z', y='intensity', kind='spectrum')
Evaluation signals
- DataFrame contains numeric columns for m/z (mass-to-charge ratio), retention time (rt), and intensity with appropriate float or int dtypes
- Column names match pyOpenMS-Viz expectations or are explicitly mapped to plot method parameters (x, y, z or specific dimension names)
- DataFrame.plot(x='m/z', y='intensity', kind='spectrum') or equivalent call executes without KeyError or TypeError exceptions
- Subsequent .plot(kind='peakmap', plot_3d=True) or other pyOpenMS-Viz plotting methods receive the DataFrame without schema validation errors
- Interactive HTML output from fig.write_html() or static plot objects are successfully generated without data dimension mismatches
Limitations
- pyOpenMS-Viz 3D PeakMap visualization (plot_3d=True) is only supported by Plotly backend, not matplotlib or Bokeh, so DataFrame structure alone does not guarantee 3D rendering success
- Column selection flexibility requires manual mapping if input data uses non-standard column names; no automatic column detection is guaranteed across all input formats
- Data quality issues (missing values, outliers, non-numeric entries in intensity or m/z columns) are not automatically handled by DataFrame preparation and may cause visualization failures downstream
Evidence
- [other] Load mass spectrometry data from an mzML or Bruker .d file into a pandas DataFrame using PyOpenMS, pymzML, pyteomics (for mzML) or alphatims (for .d format), ensuring columns for m/z, retention time, and intensity are present.: "Load mass spectrometry data from an mzML or Bruker .d file into a pandas DataFrame using PyOpenMS, pymzML, pyteomics (for mzML) or alphatims (for .d format), ensuring columns for m/z, retention time,"
- [readme] Versatile column selection for easy adaptation to different data formats: "Versatile column selection for easy adaptation to different data formats"
- [readme] Flexible plotting API that interfaces directly with Pandas DataFrames: "Flexible plotting API that interfaces directly with Pandas DataFrames"
- [readme] pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry data.: "pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry"
1---2name: pandas-dataframe-manipulation-ms-columns3description: Use when when you have raw mass spectrometry data (from mzML, Bruker .d, or CSV format) loaded into a Pandas DataFrame and need to ensure it has the correct column structure (m/z, retention time, intensity) before invoking pyOpenMS-Viz plotting functions like .plot(kind='spectrum'), .4license: CC-BY-4.05---67# pandas-dataframe-manipulation-ms-columns89## Summary1011Prepare and structure mass spectrometry data within Pandas DataFrames by organizing and selecting columns for m/z, retention time, and intensity dimensions required by pyOpenMS-Viz plotting methods. This skill ensures data is in the correct format and column names are compatible with the visualization backend.1213## When to use1415When you have raw mass spectrometry data (from mzML, Bruker .d, or CSV format) loaded into a Pandas DataFrame and need to ensure it has the correct column structure (m/z, retention time, intensity) before invoking pyOpenMS-Viz plotting functions like .plot(kind='spectrum'), .plot(kind='peakmap'), or .plot(kind='chromatogram').1617## When NOT to use1819- Data is already in a specialized mass spectrometry object format (e.g., pyOpenMS MSSpectrum, MSChromatogram) that does not need DataFrame conversion20- Column structure and naming are already validated and match pyOpenMS-Viz expectations21- Input is binary or proprietary mass spectrometry data that requires vendor-specific parsers before any DataFrame creation2223## Inputs2425- Pandas DataFrame with mass spectrometry data (loaded from mzML, Bruker .d, CSV, or similar format)26- Column names and data types present in the DataFrame27- Target plot type (spectrum, chromatogram, peakmap, mobilogram)2829## Outputs3031- Prepared Pandas DataFrame with correctly named and typed columns (m/z, retention time, intensity)32- DataFrame ready for input to pyOpenMS-Viz .plot() method3334## How to apply3536Load mass spectrometry data into a Pandas DataFrame using appropriate readers (PyOpenMS, pymzML, pyteomics for mzML, or alphatims for Bruker .d format), ensuring the resulting DataFrame contains columns for m/z (mass-to-charge ratio), retention time (rt), and intensity values. Inspect and rename columns as needed to match the expected names used by pyOpenMS-Viz (typically 'x', 'y', 'z' or domain-specific names like 'm/z', 'rt', 'intensity'). Use the 'versatile column selection' feature documented in pyOpenMS-Viz to map your DataFrame columns to the required dimensions for your chosen plot type. Verify column data types are numeric (float or int) before passing the DataFrame to the plotting method. This standardization enables seamless backend switching and ensures consistent API behavior across matplotlib, Bokeh, and Plotly backends.3738## Related tools3940- **Pandas** (DataFrame data structure and column manipulation for organizing m/z, retention time, and intensity columns)41- **PyOpenMS** (Loading and parsing mass spectrometry data from mzML and native OpenMS formats into Pandas-compatible structures)42- **pymzML** (Alternative parser for mzML mass spectrometry files into DataFrame-ready format)43- **pyteomics** (Alternative parser for mzML mass spectrometry files into DataFrame-ready format)44- **alphatims** (Parser for Bruker .d format mass spectrometry files into DataFrame-ready format)45- **pyOpenMS-Viz** (Visualization library that consumes prepared DataFrames with correctly named m/z, retention time, and intensity columns via the .plot() method) — https://github.com/OpenMS/pyopenms_viz4647## Examples4849```50ms_data = pd.read_csv('path/to/ms_data.csv')51ms_data.plot(x='m/z', y='intensity', kind='spectrum')52```5354## Evaluation signals5556- DataFrame contains numeric columns for m/z (mass-to-charge ratio), retention time (rt), and intensity with appropriate float or int dtypes57- Column names match pyOpenMS-Viz expectations or are explicitly mapped to plot method parameters (x, y, z or specific dimension names)58- DataFrame.plot(x='m/z', y='intensity', kind='spectrum') or equivalent call executes without KeyError or TypeError exceptions59- Subsequent .plot(kind='peakmap', plot_3d=True) or other pyOpenMS-Viz plotting methods receive the DataFrame without schema validation errors60- Interactive HTML output from fig.write_html() or static plot objects are successfully generated without data dimension mismatches6162## Limitations6364- pyOpenMS-Viz 3D PeakMap visualization (plot_3d=True) is only supported by Plotly backend, not matplotlib or Bokeh, so DataFrame structure alone does not guarantee 3D rendering success65- Column selection flexibility requires manual mapping if input data uses non-standard column names; no automatic column detection is guaranteed across all input formats66- Data quality issues (missing values, outliers, non-numeric entries in intensity or m/z columns) are not automatically handled by DataFrame preparation and may cause visualization failures downstream6768## Evidence6970- [other] Load mass spectrometry data from an mzML or Bruker .d file into a pandas DataFrame using PyOpenMS, pymzML, pyteomics (for mzML) or alphatims (for .d format), ensuring columns for m/z, retention time, and intensity are present.: "Load mass spectrometry data from an mzML or Bruker .d file into a pandas DataFrame using PyOpenMS, pymzML, pyteomics (for mzML) or alphatims (for .d format), ensuring columns for m/z, retention time,"71- [readme] Versatile column selection for easy adaptation to different data formats: "Versatile column selection for easy adaptation to different data formats"72- [readme] Flexible plotting API that interfaces directly with Pandas DataFrames: "Flexible plotting API that interfaces directly with Pandas DataFrames"73- [readme] pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry data.: "pyOpenMS-Viz is a Python library that provides a simple interface for extending the plotting capabilities of Pandas DataFrames for creating static or interactive visualizations of mass spectrometry"