How to Upload csv file in Jupyter

 How to Upload csv file in Jupyter





Before running this code make sure you have installed ipywidgets in your system

pip install ipywidgets





Code : 
import ipywidgets as widgets
widgets.IntSlider()
from IPython.display import display
w = widgets.IntSlider()
uploader = widgets.FileUpload(
    accept='*.csv',  # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'
    multiple=False  # True to accept multiple files upload else False
)

display(uploader)


Explanation : first we have to call the widgets that is basically going to show upload button and upload our file in jupyter
in accept either you can define what kind of file format you want to upload or left empty if you left empty it can take all kind of files in my case i have given *.csv because i want to upload csv file here

Multiple is false because i dont want to upload and store multiple files



import io
import pandas as pd
input_file = list(uploader.value.values())[0]
content = input_file['content']
content = io.StringIO(content.decode('utf-8'))
df = pd.read_csv(content)
df.head()


we have use io  To convert the uploaded file into a Pandas dataframe, you can use a BytesIO object

if you have anykind of query comment 

Post a Comment

0 Comments