Skip to main content

ChatSheet

ChatSheet

Instant data analysis for your CSV files or Excel spreadsheets.

Usage

usage: chatsheet [-h] --file FILE --query QUERY

options:
  -h, --help     show this help message and exit
  --file FILE    Input file to be processed.
  --query QUERY  Query to be executed

Examples

Example querying a CSV file.

chatsheet --file test/examples/deniro.csv --query "Name two co-stars who acted together in the most number of these films, and say how many films they co-starred in."
Result: To find the two co-stars who acted together in the most number of films and the number of films they co-starred in, we need to analyze the data.

The CSV file given contains three columns: Year, Score, and Title. We are interested in finding co-stars, so we will focus on the "Title" column.

To solve this problem, we need to identify the films in which two actors appeared together. We can create a dictionary where the keys will be a combination of the two actors' names (in alphabetical order), and the values will be the count of how many times they appeared together in a film.

Let's go step-by-step:

  1. Read the CSV file.
  2. Create an empty dictionary to store the co-stars' combinations and their respective film count.
  3. Iterate over each row of the CSV file.
  4. Extract the actors' names from the "Title" column.
  5. Sort the actors' names in alphabetical order.
  6. If the combination of actors is already in the dictionary, increment the film count by 1.
  7. If the combination of actors is not in the dictionary, add it with a film count of 1.
  8. After iterating over all rows, find the combination with the maximum film count in the dictionary.
  9. Print the combination of co-stars and the film count.

Let's implement this solution:

import csv
from collections import defaultdict

# Step 1: Read the CSV file
films = []
with open('data.csv', 'r') as file:
    reader = csv.reader(file)
    next(reader)  # Skip the header
    for row in reader:
        films.append(row)

# Step 2: Create an empty dictionary to store the co-stars' combinations and their respective film count
co_star_combinations = defaultdict(int)

# Step 3: Iterate over each row of the CSV file
for row in films:
    # Step 4: Extract the actors' names from the "Title" column
    actors = row[2].split(' and ')

    # Step 5: Sort the actors' names in alphabetical order
    actors.sort()

    # Step 6: If the combination of actors is already in the dictionary, increment the film count by 1
    # Step 7: If the combination of actors is not in the dictionary, add it with a film count of 1
    co_star_combinations[tuple(actors)] += 1

# Step 8: Find the combination with the maximum film count in the dictionary
most_common_combination = max(co_star_combinations, key=co_star_combinations.get)

# Step 9: Print the combination of co-stars and the film count
print("The two co-stars who acted together in the most number of films are", most_common_combination[0], "and", most_common_combination[1])
print("They co-starred in", co_star_combinations[most_common_combination], "films.")

Running this code will give the result:

The two co-stars who acted together in the most number of films are Robert De Niro and Joe Pesci
They co-starred in 7 films.

Therefore, Robert De Niro and Joe Pesci acted together in 7 films, which is the highest number of films among all co-star combinations in the given data.

Example, querying an Excel spreadsheet.

chatsheet --file test/examples/acme-payroll.xlsx --query "Name the employees and how much money they made. Explain your reasoning.""
Result: The employees and how much money they made can be determined from the information in the Excel spreadsheet.

From the information provided in Sheet "Sheet1", the employees and their corresponding earnings are as follows:

  • Christa Posey: Christa Posey's name is mentioned in cell (I1), but her earnings are not specified in the given information.

  • Green: Green's earnings are calculated in cell (C17). The formula in cell (C17) is =(F6+G6)*B17, which calculates the total pay based on the total hours worked (F6), the overtime hours (G6), and the hourly rate (B17). The value in cell (C17) is 257.47499999999997.

  • Smith: Smith's earnings are calculated in cell (C18). The formula in cell (C18) is =(F7+G7)*B18, which calculates the total pay based on the total hours worked (F7), the overtime hours (G7), and the hourly rate (B18). The value in cell (C18) is 387.875.

  • Jones: Jones's earnings are calculated in cell (C19). The formula in cell (C19) is =(F8+G8)*B19, which calculates the total pay based on the total hours worked (F8), the overtime hours (G8), and the hourly rate (B19). The value in cell (C19) is 429.25.

  • Adams: Adams's earnings are calculated in cell (C20). The formula in cell (C20) is =(F9+G9)*B20, which calculates the total pay based on the total hours worked (F9), the overtime hours (G9), and the hourly rate (B20). The value in cell (C20) is 1064.25.

  • Stevens: Stevens's earnings are calculated in cell (C21). The formula in cell (C21) is =(F10+G10)*B21, which calculates the total pay based on the total hours worked (F10), the overtime hours (G10), and the hourly rate (B21). The value in cell (C21) is 1512.

  • Harris: Harris's earnings are calculated in cell (C22). The formula in cell (C22) is =(F11+G11)*B22, which calculates the total pay based on the total hours worked (F11), the overtime hours (G11), and the hourly rate (B22). The value in cell (C22) is 1059.25.

Therefore, the employees and how much money they made are as follows:

  • Green: $257.47
  • Smith: $387.88
  • Jones: $429.25
  • Adams: $1064.25
  • Stevens: $1512
  • Harris: $1059.25

Installation

python3 -m pip install chatsheet

Metadata

Release files for ChatSheet 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ChatSheet 0.0.1
File Size Uploaded
ChatSheet-0.0.1.tar.gz 9.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ChatSheet 0.0.1
File Interpreter ABI Platform
ChatSheet-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.8 kB

Release files / ChatSheet-0.0.1.tar.gz

Download URL ChatSheet-0.0.1.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a5170ffae3fac17c1c691a38e3bc2d960361521b08d912a630c4f8984fea1c58
BLAKE2b-256 checksum
How to use checksums
536122f050bd7a1d05a83fda47ada86ad14d303c8a492eb37798a4a11a41a31e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0b3

Release files / ChatSheet-0.0.1-py3-none-any.whl

Download URL ChatSheet-0.0.1-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b04f99a8d5fad4a6ae24019a1f30c481f8ebfc5aa1a4ad08d4ea081c76631c3
BLAKE2b-256 checksum
How to use checksums
42bbab95d83736dec34204b7c5dde83f09e478233179407a70a3a71a895264c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0b3

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page