Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

python - Store tabular data in Class

Is there any standard and pythonic way to store a small table (consisting of a few rows and a few columns) of constant values as a field in a my class definition?

I'm wondering if it is standard to define such a table of defaults in the class definition, or it is recommended to define it somewhere else.

In fact, depending on some user input, I want to use some row of this table as default value to instantiate my class.

question from:https://stackoverflow.com/questions/65641330/store-tabular-data-in-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have many possibilities here, you can use multidimensional lists (list in lists) or numpy arrays (https://numpy.org/doc/stable/reference/generated/numpy.array.html) or pandas dataframes (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html).

Pandas dataframe come along with a lot functionality for tabular data, so look at the documentation of them and consider if this fits for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...