<jupyter_start><jupyter_text>![LOGO](../tutorial/tutorial_notebooks/img/MODIN_ver2_hrz.png)  modin.spreadsheet`modin.spreadsheet` is a Jupyter notebook widget that allows users to interact with Modin DataFrames in a spreadsheet-like fashion while taking advantage of the underlying capabilities of Modin. The widget makes it quick and easy to explore, sort, filter, edit data and export reproducible code. This tutorial will showcase how to use `modin.spreadsheet`. Before starting, please install the required packages using `pip install -r requirements.txt` in the current directory. Then just run the cells; no editing required!<jupyter_code># Please install the required packages using `pip install -r requirements.txt` in the current directory
# For all ways to install Modin see official documentation at:
# https://modin.readthedocs.io/en/latest/installation.html
import modin.pandas as pd
import modin.spreadsheet as mss<jupyter_output><empty_output><jupyter_text>Create a Modin DataFrameThe following cells creates a DataFrame using a NYC taxi dataset.<jupyter_code>columns_names = [
        "trip_id", "vendor_id", "pickup_datetime", "dropoff_datetime", "store_and_fwd_flag",
        "rate_code_id", "pickup_longitude", "pickup_latitude", "dropoff_longitude", "dropoff_latitude",
        "passenger_count", "trip_distance", "fare_amount", "extra", "mta_tax", "tip_amount",
        "tolls_amount", "ehail_fee", "improvement_surcharge", "total_amount", "payment_type",
        "trip_type", "pickup", "dropoff", "cab_type", "precipitation", "snow_depth", "snowfall",
        "max_temperature", "min_temperature", "average_wind_speed", "pickup_nyct2010_gid",
        "pickup_ctlabel", "pickup_borocode", "pickup_boroname", "pickup_ct2010",
        "pickup_boroct2010", "pickup_cdeligibil", "pickup_ntacode", "pickup_ntaname", "pickup_puma",
        "dropoff_nyct2010_gid", "dropoff_ctlabel", "dropoff_borocode", "dropoff_boroname",
        "dropoff_ct2010", "dropoff_boroct2010", "dropoff_cdeligibil", "dropoff_ntacode",
        "dropoff_ntaname", "dropoff_puma",
    ]
parse_dates=["pickup_datetime", "dropoff_datetime"]
df = pd.read_csv('s3://modin-datasets/trips_data.csv', names=columns_names,
                header=None, parse_dates=parse_dates)
df<jupyter_output><empty_output><jupyter_text>Generate a spreadsheet widget with the DataFrame`mss.from_dataframe` takes in a DataFrame, optional configuration options, and returns a `SpreadsheetWidget`, which contains all the logic for displaying the spreadsheet view of the DataFrame. The object returned will not be rendered unless displayed.<jupyter_code>spreadsheet = mss.from_dataframe(df)<jupyter_output><empty_output><jupyter_text>Displaying the SpreadsheetThe widget is displayed when the widget is returned by an input cell or passed to the `display` function e.g. `display(spreadsheet)`. When displayed, the SpreadsheetWidget will generate a transformation history cell that contains a record of the transformations applied to the DataFrame unless the cell already exists or the feature is disabled. Basic Usage`from_dataframe` creates a copy of the input DataFrame, so changes do not alter the original DataFrame.**Filter** - Each column can be filtered according to its datatype using the filter button to the right of the column header. Any number of columns can be filtered simultaneously.\**Sort** - Each column can be sorted by clicking on the column header. Assumptions on the order of the data should only be made according to the latest sort i.e. the 2nd last sort may not be in order even if grouped by the duplicates in the last sorted column.\**Cell Edit** - Double click on a cell to edit its value.\**Add Row**(toolbar) - Click on the `Add Row` button in the toolbar to duplicate the last row in the DataFrame.\**Remove Row**(toolbar) - Select row(s) on the spreadsheet and click the `Remove Row` button in the toolbar to remove them.\**Reset Filters**(toolbar) - Click on the `Reset Filters` button in the toolbar to remove all filters on the data.\**Reset Sort**(toolbar) - Click on the `Reset Sort` button in the toolbar to remove any sorting on the data. Transformation History and Reproducible CodeThe widget records the history of transformations, such as filtering, that occur on the spreadsheet. These transformations are updated in the `spreadsheet transformation history` cell as they happen and can be easily copied for reproducibility. The history can be cleared using the `Clear History` button in the toolbar.**Try making some changes to the spreadsheet!**<jupyter_code>spreadsheet<jupyter_output><empty_output><jupyter_text>Exporting Changes`to_dataframe` takes in a `SpreadsheetWidget` and returns a copy of the DataFrame reflecting the current state of the UI on the widget. Specifically, any filters, edits, or sorts will be applied on the returned Dataframe.**Export a DataFrame after making some changes on the spreadsheet UI**<jupyter_code>changed_df = mss.to_dataframe(spreadsheet)
changed_df<jupyter_output><empty_output><jupyter_text>SpreadsheetWidget APIThe API on `SpreadsheetWidget` allows users to replicate some of the functionality on the GUI, but also provides other functionality such as applying the transformation history on another DataFrame or getting the DataFrame that matches the spreadsheet state like `to_dataframe`.<jupyter_code># Duplicates the `Reset Filters` button
spreadsheet.reset_filters()
# Duplicates the `Reset Sort` button
spreadsheet.reset_sort()
# Duplicates the `Clear History` button
spreadsheet.clear_history()
# Gets the modified DataFrame that matches the changes to the spreadsheet
# This is the same functionality as `mss.to_dataframe`
spreadsheet.get_changed_df()<jupyter_output><empty_output><jupyter_text>Retrieving and Applying Transformation History The transformation history can be retrieved as a list of code snippets using the `get_history` API. The `apply_history` API will apply the transformations on the input DataFrame and return the resultant DataFrame.<jupyter_code>spreadsheet.get_history()
another_df = df.copy()
spreadsheet.apply_history(another_df)<jupyter_output><empty_output><jupyter_text>Additional ExampleHere is another example of how to use `from_dataframe` with configuration options.<jupyter_code>mss.from_dataframe(df, show_toolbar=False, grid_options={'forceFitColumns': False, 'editable': False, 'highlightSelectedCell': True})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07817842710599938, 'fraction_numerical': 0.00419645632576935, 'mean_word_length': 6.110497237569061, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '154681', 'license': 'ECL-2.0', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1747, 'n_words': 688, 'path': 'examples/spreadsheet/tutorial.ipynb', 'repo_name': 'igalink/modin', 'size': '6434'}