Import Files
Once the file is uploaded, it can be accessed in the Python or R blocks, and the files can be of any type.
import pandas as pd
df = pd.read_csv("housing.csv")file = "housing.csv"
df = read.csv(file)import json
# Open and read the raw content of the file
with open('./testdata.json', 'r') as json_file:
content = json_file.read()
# Print the first few characters to understand the structure
print("First 500 characters of the file:")
print(content[:500]) # Adjust the number as needed for better understanding
# Check if the content contains multiple JSON objects
try:
data = json.loads(content)
print("Single JSON object loaded successfully.")
except json.JSONDecodeError as e:
print(f"JSONDecodeError: {e}")
# Possible handling for multiple JSON objects:
# Assuming the objects are newline-separated
segments = content.splitlines() # Split by lines (change the delimiter if needed)
parsed_data = []
for segment in segments:
if segment.strip(): # Skip empty lines
try:
parsed_data.append(json.loads(segment))
except json.JSONDecodeError as segment_error:
print(f"Failed to parse segment: {segment_error}")
print(f"Parsed {len(parsed_data)} JSON objects/segments successfully.")
# For demonstration purposes, let's print the parsed objects
for i, obj in enumerate(parsed_data):
print(f"Object {i+1}: {obj}")
Last updated

