Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, where are the data for tips under Plotly from?

Tags:

python

plotly

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]
like image 274
neutralname Avatar asked Apr 24 '26 17:04

neutralname


1 Answers

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())
like image 171
furas Avatar answered Apr 27 '26 07:04

furas