https://github.com/Axnjr/csv-parser-utils
Homework task for SWE position at Redhat.
https://github.com/Axnjr/csv-parser-utils
csv data dataanalysis datatools pandas python
Last synced: 4 months ago
JSON representation
Homework task for SWE position at Redhat.
- Host: GitHub
- URL: https://github.com/Axnjr/csv-parser-utils
- Owner: Axnjr
- Created: 2025-02-07T11:27:24.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-07T11:35:30.000Z (about 1 year ago)
- Last Synced: 2025-02-07T12:37:45.706Z (about 1 year ago)
- Topics: csv, data, dataanalysis, datatools, pandas, python
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `CSV_Utils/py_go_rs`
## Public Methods:
- `display_csv()`
- `filter_rows()`
- `sort_csv()`
- `aggregate_column()`
- `count_valid_palindromes()`
- `write_csv()`
- `remove_duplicates()`
- `replace_all_vals()`
- `reaplace_first_val()`
- `read_csv()`
- `summerize()`
- `export_json()`
- `apply_func()`
- `output_processed_csv()`
## Private Methods:
- `_update_csv()`
- `_validate()`
- `_load_csv()`
## Usage / test cases
```py
def run_test1():
sample_data = [
['Name', 'Age', 'Score'],
['Alice', '23', '85'],
['Bob', '30', '90'],
['Charlie', '25', '78']
]
test_file = 'sample.csv'
CSV_Utils_Py.write_csv(test_file, sample_data)
# ------------------------------------------------------------------------------------------------------------------ #
def run_test2():
df = CSV_Utils_Py("python/ppl.csv")
df.display_csv()
# df.output_processed_csv("output_ppl.csv")
filtered_data = df.filter_rows('Job Title', lambda x: x == "Games developer")
print("Filtered Data:", filtered_data)
sorted_data = df.sort_csv('Phone', ascending=False)
print("Sorted Data:", sorted_data)
total_score = df.aggregate_column('Index', 'sum')
print("Total Score:", total_score)
palindrome_count = df.count_valid_palindromes()
print("Valid Palindromes Count:", palindrome_count)
# os.remove(test_file)
# data = pd.read_csv("python/ppl.csv")
# print(data.to_string())
# ------------------------------------------------------------------------------------------------------------------ #
def run_test3():
df = CSV_Utils_Py("python/fruits.csv")
df.display_csv()
df.output_processed_csv("output_fruits.csv")
filtered_data = df.filter_rows('Price', lambda x: float(x) > 1.0, True)
print("Filtered Data:", filtered_data)
sorted_data = df.sort_csv('Date', ascending=False)
print("Sorted Data:", sorted_data)
total_score = df.aggregate_column('Price', 'sum')
print("Total price:", total_score)
palindrome_count = df.count_valid_palindromes()
print("Valid Palindromes Count:", palindrome_count)
# ------------------------------------------------------------------------------------------------------------------ #
def run_test4():
df = CSV_Utils_Py("./ppl.csv")
# replace all "First Name": Shelby to Radha
df.replace_all_vals("First Name", "Shelby", "Radha")
# removes duplicates from "Job" Column
df.remove_duplicates("Job Tittle")
# Converts all first names to uppercase
df.apply_func("First Name", lambda s: s.upper())
# Export data to JSON
json_data = df.export_json("ppl.json")
print(json_data)
# counts palindromes in the csv file
df.count_valid_palindromes()
# show the summary of the csv file after analysis
df.summerize()
if __name__ == "__main__":
run_test1()
run_test2()
run_test3()
run_test4()
```