I've worked on a python code that automates data frames reading for multiple extensions and prints the DF's first 100 lines as well as the Types of it's columns with the possibility to add more things within the same simple function, I'm currently working on making the response in a JSON format but still unable to do so since this is my first time working with Json API as I'm more data analysis/science than programming Thanks for your help & suggestions
import os
import modin.pandas as pd
def sqlread(con_w_sql, sep='#'):
con, sql = special_path.split(sep)
df = pd.read_sql(sql, con)
return df.head()
readict = {
".csv": {
"read": pd.read_csv
},
".tsv": {
"read": pd.read_csv
},
".json": {
"read": pd.read_json
},
".xlsx": {
"read": pd.read_excel
},
".xml": {
"read": pd.read_xml
},
".xls": {
"read": pd.read_excel
},
".hdf": {
"read": pd.read_hdf
},
".sql": {
"read": sqlread
}
}
def read_any(file):
_, ext = os.path.splitext(file)
df = readict[ext]["read"](file)
return df.head(100), df.dtypes
file = input("enter the path to the file you want to open : ")
read_any(file)