# Loading our own datasets

**URL:** <https://discuss.streamlit.io/t/loading-our-own-datasets/7118>\
**Category:** Random\
**Tags:** pandas\
**Created:** [November 13, 2020, 2:53pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118 "2020-11-13T14:53:23Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Byri\_Manoj](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/byri_manoj/32/3961_2.png) [@Byri\_Manoj](https://discuss.streamlit.io/u/Byri_Manoj)\
**Post date:** [November 13, 2020, 2:53pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/1 "2020-11-13T14:53:23Z")

</div>

Hey guys, I’ve started learning streamlit just today and I have got a doubt on how to load our own datasets in excel and CSV formats into the streamlit? I have seen loading datasets from the traditional sklearn datasets only in tutorial videos. So please help me with this.

It would be really helpful if someone solves this for me!

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [November 13, 2020, 4:02pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/2 "2020-11-13T16:02:07Z")

</div>

Hi @Byri_Manoj, welcome to the Streamlit community!

You can use pandas to read in CSV and Excel files:

> **[pandas.read\_csv — pandas 1.1.4 documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html#pandas.read_csv)**

> **[pandas.read\_excel — pandas 1.1.4 documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html)**

Good luck on your learning journey!

Best,  
Randy

---

<div class="post-metadata">

**Author:** ![andfanilo](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/andfanilo/32/1040_2.png) [@andfanilo](https://discuss.streamlit.io/u/andfanilo)\
**Post date:** [November 13, 2020, 4:02pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/3 "2020-11-13T16:02:21Z")

</div>

Hey @Byri_Manoj, welcome to the community 🙂

Well if you know how to load a dataset with Pandas, you’re already 90% done! Imagine that Streamlit is a layer over your Python code to visualize data.

So you can load your data the way you know using Pandas, then use Streamlit to visualize the data:

```python
# app.py, run with 'streamlit run app.py'
import pandas as pd
import streamlit as st

df = pd.read_csv("./data/titanic.csv") # read a CSV file inside the 'data" folder next to 'app.py'
# df = pd.read_excel(...) # will work for Excel files

st.title("Hello world!") # add a title
st.write(df) # visualize my dataframe in the Streamlit app

```

 ![image](https://global.discourse-cdn.com/streamlit/original/2X/e/ef18106afc17a98c56d4e958dbf7b788292541f4.png)

Now you can edit the path to the file in your Streamlit script, and Streamlit will automatically rerun in the background to load the new dataframe and display its content immediately. Nice!

There’s a more interactive way to specify files with the [file uploader](https://docs.streamlit.io/en/stable/api.html#streamlit.file_uploader). Basically Streamlit it will send the file as a buffer to Python, and `pd.read_csv` and `pd.read_excel` know how to deal with them!

```python
import pandas as pd
import streamlit as st

st.title("Hello world!")

uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
  df = pd.read_csv(uploaded_file)
  st.write(dataframe)

```

 ![demo](https://global.discourse-cdn.com/streamlit/original/2X/e/e2e6aedb8533ea246200aff9509e00e212e28907.gif)

Other than that, all the rest is Python code. So you’re free to manipulate your dataframe in `df` the way you want, and if you need to show something on Streamlit, try `st.write(<your variable>)` to display it, it works on a lot of things, Pandas Dataframes, Matplotlib graphs, markdown text

For example in the following I compute a Maplotlib plot and want to display it in Streamlit:

```python
import matplotlib.pyplot as plt
import pandas as pd
import streamlit as st

st.title("Hello world!")

uploaded_file = st.file_uploader("Choose a file")
if uploaded_file is not None:
  df = pd.read_csv(uploaded_file)
  st.write(df)

  # Add some matplotlib code !
  fig, ax = plt.subplots()
  df.hist(
    bins=8,
    column="Age",
    grid=False,
    figsize=(8, 8),
    color="#86bf91",
    zorder=2,
    rwidth=0.9,
    ax=ax,
  )
  st.write(fig)

```

 ![image](https://global.discourse-cdn.com/streamlit/original/2X/3/39d5fa83bf94cfd3ee629a8b686da2787152272c.png)

And don’t forget, it’s all rerendered in real time !

 ![demo](https://global.discourse-cdn.com/streamlit/original/2X/d/db00bdfb7ae86a5962c40e6be30bb832a5d0e962.gif)

That’s the intro 🙂 hope it helps!

Fanilo

---

<div class="post-metadata">

**Author:** ![irrelevantRyan](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/irrelevantryan/32/11827_2.png) [@irrelevantRyan](https://discuss.streamlit.io/u/irrelevantRyan)\
**Post date:** [November 26, 2021, 10:11pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/4 "2021-11-26T22:11:48Z")

</div>

> [@andfanilo](#):
>
> `df = pd.read_csv("./data/titanic.csv")`

Hey,

This worked when I loaded datasets locally. However, when I wanted to load datasets when the app is hosted on streamlit servers it gave me this error.

FileNotFoundError: [Errno 2] No such file or directory: ‘./data/experimental\_data.csv’

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![Sam\_Blades](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/sam_blades/32/12156_2.png) [@Sam\_Blades](https://discuss.streamlit.io/u/Sam_Blades)\
**Post date:** [December 8, 2021, 6:20pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/5 "2021-12-08T18:20:14Z")

</div>

I have the same question. I want users of my web app to load data stored locally on their PC into the streamlit web app and then have it plotted.

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [December 8, 2021, 6:45pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/6 "2021-12-08T18:45:44Z")

</div>

> [@irrelevantRyan](#):
>
> FileNotFoundError: [Errno 2] No such file or directory: ‘./data/experimental\_data.csv’

Hi @irrelevantRyan, welcome to the Streamlit community! Sorry I missed this before…

What is happening is that you are using a relative reference to the file, which presumes you start in a specific directory. The usual recommendation is to use pathlib, as demonstrated in this answer:

> [@Issues with Reading in Dataset (FileNotFoundError)](https://discuss.streamlit.io/t/issues-with-reading-in-dataset-filenotfounderror/12414/2):
>
> Hi @v4_gadkari The strings you are referencing are relative to the current working directory (cwd) when you run the app locally. I’m not sure what the cwd is on streamlit sharing, but you can overcome this issue with the pathlib or os modules for the standard library. Below example using the pathlib module as it has a more readable pattern. from pathlib import Path garret\_burhenn\_pitches\_csv = Path(\_\_file\_\_).parents[1] / 'GarretBurhennData/Garret\_Burhenn\_Pitches.csv' To explain above a litt…

Best,  
Randy

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [December 8, 2021, 6:46pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/7 "2021-12-08T18:46:48Z")

</div>

> [@Sam\_Blades](#):
>
> I have the same question. I want users of my web app to load data stored locally on their PC into the streamlit web app and then have it plotted.

HI @Sam_Blades -

It’s important to realize that once your app is deployed, the users must transfer the data through the browser. This is done using `st.file_uploader`:

> **[st.file\_uploader - Streamlit Docs](https://docs.streamlit.io/library/api-reference/widgets/st.file_uploader)**
>
> st.file\_uploader displays a file uploader widget.

Best,  
Randy

---

<div class="post-metadata">

**Author:** ![Sai\_Ram\_k](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/sai_ram_k/32/7015_2.png) [@Sai\_Ram\_k](https://discuss.streamlit.io/u/Sai_Ram_k)\
**Post date:** [December 9, 2021, 5:40am UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/8 "2021-12-09T05:40:02Z")

</div>

Greetings @randyzwitch ,  
Could you please help me with my query as well.

> [@Map Co-Ordinates not appearing when using st.map(df)](https://discuss.streamlit.io/t/map-co-ordinates-not-appearing-when-using-st-map-df/19710):
>
> Greetings, I was just experimenting with the st.map(df) and I was not getting the expected result. I just get a blank without any points being plotted. Requesting the community to guide me. I have implemented the following: I have already taken the dataframe input using file\_uploader try: lat= st.selectbox("Select Latitudes column " , df.columns, key="8") long=st.selectbox("Select Longitudes column " , df.columns, key="9") …

---

<div class="post-metadata">

**Author:** ![Amanweb200](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@Amanweb200](https://discuss.streamlit.io/u/Amanweb200)\
**Post date:** [February 18, 2022, 2:14pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/9 "2022-02-18T14:14:25Z")

</div>

Hi I did that but while deploying it is still throwing me the error could you help me ?

---

<div class="post-metadata">

**Author:** ![aleivaar](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@aleivaar](https://discuss.streamlit.io/u/aleivaar)\
**Post date:** [August 24, 2022, 11:25pm UTC](https://discuss.streamlit.io/t/loading-our-own-datasets/7118/10 "2022-08-24T23:25:36Z")

</div>

I tried the same path using pathlib and it doesn’t work. Any help is appreciated. Thank you
