p2
This commit is contained in:
2931
WS24_25/PyCharm/pythonProject/P2/AmesHousing.csv
Normal file
2931
WS24_25/PyCharm/pythonProject/P2/AmesHousing.csv
Normal file
File diff suppressed because it is too large
Load Diff
55672
WS24_25/PyCharm/pythonProject/P2/AmesHousing.json
Normal file
55672
WS24_25/PyCharm/pythonProject/P2/AmesHousing.json
Normal file
File diff suppressed because it is too large
Load Diff
29
WS24_25/PyCharm/pythonProject/P2/cvsToJson.py
Normal file
29
WS24_25/PyCharm/pythonProject/P2/cvsToJson.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
|
||||
|
||||
def csv_to_json(input_file: str, output_file: str):
|
||||
data = []
|
||||
|
||||
# Step 1: Read the CSV file manually
|
||||
with open(input_file, 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
# Step 2: Parse the first line to get the headers
|
||||
headers = lines[0].strip().split(';')
|
||||
|
||||
# Step 3: Parse the subsequent lines to get the data
|
||||
for line in lines[1:]:
|
||||
values = line.strip().split(';')
|
||||
# Create a dictionary for each row
|
||||
row_dict = {headers[i]: values[i] for i in range(len(headers))}
|
||||
data.append(row_dict)
|
||||
|
||||
# Step 4: Save the data to a JSON file
|
||||
with open(output_file, 'w') as json_file:
|
||||
json.dump(data, json_file, indent=4)
|
||||
|
||||
|
||||
# Usage
|
||||
input_csv_file = 'AmesHousing.csv'
|
||||
output_json_file = 'AmesHousing.json'
|
||||
csv_to_json(input_csv_file, output_json_file)
|
||||
19
WS24_25/PyCharm/pythonProject/P2/summary.py
Normal file
19
WS24_25/PyCharm/pythonProject/P2/summary.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def summarize_csv(file_path: str):
|
||||
# Step 1: Load the CSV file using pandas
|
||||
df = pd.read_csv(file_path, delimiter=';')
|
||||
|
||||
# Step 2: Print general information about the data
|
||||
print("Data Info:")
|
||||
print(df.info())
|
||||
|
||||
# Step 3: Print statistical summary of the numerical columns
|
||||
print("\nStatistical Summary:")
|
||||
print(df.describe())
|
||||
|
||||
|
||||
# Usage
|
||||
input_csv_file = 'AmesHousing.csv'
|
||||
summarize_csv(input_csv_file)
|
||||
Reference in New Issue
Block a user