3
import plotly.express as px
tips = px.data.tips()
tips
px.histogram(tips, x="total_bill", y="tip", histfunc="sum", color="smoker")

just a few lines and there are already all this data in "tips", I am very confused where do those number coming from? Thanks a lot tips

Out[125]: 
     total_bill   tip     sex smoker   day    time  size
0         16.99  1.01  Female     No   Sun  Dinner     2
1         10.34  1.66    Male     No   Sun  Dinner     3
2         21.01  3.50    Male     No   Sun  Dinner     3
3         23.68  3.31    Male     No   Sun  Dinner     2
4         24.59  3.61  Female     No   Sun  Dinner     4
..          ...   ...     ...    ...   ...     ...   ...
239       29.03  5.92    Male     No   Sat  Dinner     3
240       27.18  2.00  Female    Yes   Sat  Dinner     2
241       22.67  2.00    Male    Yes   Sat  Dinner     2
242       17.82  1.75    Male     No   Sat  Dinner     2
243       18.78  3.00  Female     No  Thur  Dinner     2

[244 rows x 7 columns]

2 Answers 2

7

Using

import plotly.express as px

print(px.data.__file__)

you can see path to source code and check it.

Digging in source code I found that on Linux data are in folder

/usr/local/lib/python3.7/dist-packages/plotly/package_data/datasets/

as .csv files compressed to .gz files so pandas.read_csv() can read it without problem.
And tips() uses pandas.read_csv() to read it.


You can display other functions in px.data which reads datasets using dir()

import plotly.express as px

for name in dir(px.data):
    if '__' not in name:
        print(name)

Result

absolute_import
carshare
election
gapminder
iris
tips
wind

Probably all of them (except absolute_import) are functions which reads some .gz file with data.

print(px.data.carshare())
print(px.data.election())
print(px.data.gapminder())
print(px.data.iris())
print(px.data.tips())
print(px.data.wind())
Sign up to request clarification or add additional context in comments.

Comments

0

There are a few small dataset you can import from plotly.express.

When you write tips = px.data.tips() It’s import this data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.