当前位置:网站首页>Dimension and format of data
Dimension and format of data
2022-07-04 06:16:00 【Sweet cake】
We live in a multidimensional world , The same goes for data . The movie 《 The matrix 》 in , Human beings live in a world of data , Everything you see , Including taste, smell and so on , Are made up of data . Machines connect humans through matrices , The basic elements that make up the world , It's data .
The dimension of data is everywhere . generally , The dimension of data is the organization form of data , It can be divided into One-dimensional data , Two dimensional data , Multidimensional data and high-dimensional data :
- One dimensional data is composed of ordered or disordered data with equal relationship in a linear manner , Such as lists and collections , Corresponding to the array in Mathematics .
- Two dimensional data , It consists of multiple one-dimensional data , It's a combination of one-dimensional data , Also known as tabular data , As listing , Corresponding to matrix in Mathematics .
- Multidimensional data is the expansion of one-dimensional or two-dimensional data on new dimensions , such as Time dimension .
- High dimensional data shows the complex structure between data in a simple binary relationship , It can be nested in multiple layers , Such as a dictionary ,JSON,XML etc. .
1、 One-dimensional data
One dimensional data is the simplest type of data organization . Its expression has two forms , If the data is in order , Use list type []; If the data is out of order , Then use the collection type {}.
1.1 One dimensional data storage
There are mainly the following ways :
Separator | Example | remarks |
---|---|---|
Space | Apple Banana Plum Mango. durian | There must be no spaces in the element |
comma | Apple , Banana , Plum , Mango. , durian | There cannot be a comma in the element |
A newline | Apple \n Banana \n Plum \n Mango. \n durian | |
Special symbols | Apple @ Banana @ Plum @ Mango. @ durian |
Be careful , The above punctuation marks are English punctuation marks , That is, half angle symbol .
Regardless of any way of segmentation and representation , One dimensional data are linear ,for Loops can traverse data , And then each data is processed .
1.2 Reading of one-dimensional data
txt=open('file').read() #file Is the path and name of the file to be read
ls=txt.split() # Divide according to the corresponding separator
txt.close()
1.3 One dimensional data writing
ls=[...] # To write to the list
f=open('file','w') # To write a file
f.write(' ',join(ls)) # To write the separator
f.close()
2、 Two dimensional data
The common representation of two-dimensional data is two-dimensional list , Similar to plane rectangular coordinate system , By line (row) And column (column) To determine an element . Each element in the outer list can correspond to one line , It can also correspond to a column , You need to use two layers for Loop through each element .
2.1 Two dimensional data storage
Two dimensional data are often used CSV(Comma-Separated Values) Format to store .CSV Each line of the file is one-dimensional data , Whole CSV The file is a two-dimensional data .
CSV It is an internationally used 、 Two dimensional data storage format , Is the standard format for data conversion , General with .csv Extension name , for Excel Wait for the editing software to read 、 Edit and save , The specifications are as follows :
- Leave the beginning blank , Behavior unit .
- With or without header , The header is on the first line of the file , It can be stored separately .
- One line of data does not cross lines , There is no vacancy .
- Comma with half angle (,) As separator , Missing elements should also be preserved .
- If there are half quotes in the column contents ("), Replace with half angle double quotes ("") escape .
- File read 、 Writing quotation mark , Comma reverse rule interoperability .
- Internal code format is not limited , for ASCII、Unicode Or other .
- Special characters are not supported
CSV Data is stored in rows or columns depending on the program , General indexing habits ls[row][column] , First, then .
With 2020 Comprehensive ranking of national hospitals For example
ranking | Hospital name | The reputation of the specialist | Scientific research and academic research | Comprehensive score |
1 | Peking Union Hospital, Chinese Academy of Medical Sciences | 80 | 15.396 | 95.396 |
2 | West China Hospital of Sichuan University | 69.57 | 20 | 89.57 |
3 | PLA General Hospital | 58.658 | 12.734 | 71.392 |
4 | Zhongshan Hospital Affiliated to Fudan University | 32.254 | 12.032 | 44.286 |
5 | Ruijin Hospital Affiliated to medical school of Shanghai Jiaotong University | 32.807 | 11.436 | 44.243 |
6 | Tongji Hospital Affiliated to Tongji Medical College of Huazhong University of science and technology | 23.676 | 14.15 | 37.826 |
7 | Huashan Hospital Affiliated to Fudan University | 25.232 | 9.415 | 34.647 |
8 | The First Affiliated Hospital of Sun Yat sen University | 23.345 | 10.93 | 34.275 |
9 | Union Hospital Affiliated to Tongji Medical College of Huazhong University of science and Technology | 19.485 | 14.1 | 33.585 |
10 | The First Affiliated Hospital of Medical College of Zhejiang University | 17.002 | 14.06 | 31.062 |
The file is stored as Hospital ranking .csv, The format is :
ranking , Hospital name , The reputation of the specialist , Scientific research and academic research , Comprehensive score
1, Peking Union Hospital, Chinese Academy of Medical Sciences ,80,15.396,95.396
2, West China Hospital of Sichuan University ,69.57,20,89.57
3, PLA General Hospital ,58.658,12.734,71.392
4, Zhongshan Hospital Affiliated to Fudan University ,32.254,12.032,44.286
5, Ruijin Hospital Affiliated to medical school of Shanghai Jiaotong University ,32.807,11.436,44.243
6, Tongji Hospital Affiliated to Tongji Medical College of Huazhong University of science and technology ,23.676,14.15,37.826
7, Huashan Hospital Affiliated to Fudan University ,25.232,9.415,34.647
8, The First Affiliated Hospital of Sun Yat sen University ,23.345,10.93,34.275
9, Union Hospital Affiliated to Tongji Medical College of Huazhong University of science and Technology ,19.485,14.1,33.585
10, The First Affiliated Hospital of Medical College of Zhejiang University ,17.002,14.06,31.062
2.2 Reading of two-dimensional data
f=open(' Hospital ranking .csv')
ls=[]
for line in f:
line=line.replace('\n','') # Or to .strip('\n') Function delete carriage return
ls.append(line.split(','))
for line in ls[:4]: # Print the top three
line=','.joint(line)
print(line)
f.close()
ranking , Hospital name , The reputation of the specialist , Scientific research and academic research , Comprehensive score
1, Peking Union Hospital, Chinese Academy of Medical Sciences ,80,15.396,95.396
2, West China Hospital of Sichuan University ,69.57,20,89.57
3, PLA General Hospital ,58.658,12.734,71.392
>>>
2.3 Writing of two-dimensional data
Overwrite writing and append writing are different
wls=[[' ranking ', ' Hospital name ', ' The reputation of the specialist ', ' Scientific research and academic research ', ' Comprehensive score '],\
['1', ' Peking Union Hospital, Chinese Academy of Medical Sciences ', '80', '15.396', '95.396'],\
['2', ' West China Hospital of Sichuan University ', '69.57', '20', '89.57'],\
['3', ' PLA General Hospital ', '58.658', '12.734', '71.392']]
file=open('new.csv','w')
for item in wls:
file.write(','.join(item)+'\n')
file.close()
The result is to generate files in the current directory new.csv, Its storage format is :
ranking , Hospital name , The reputation of the specialist , Scientific research and academic research , Comprehensive score
1, Peking Union Hospital, Chinese Academy of Medical Sciences ,80,15.396,95.396
2, West China Hospital of Sichuan University ,69.57,20,89.57
3, PLA General Hospital ,58.658,12.734,71.392
Append write , The original document has been rewritten :
als=[['11',' Xijing Hospital of Air Force Military Medical University ','22.974','7.771','30.745'],\
['12',' The first hospital of Peking University ','20.523','9.398','29.921']]
f=open(' Hospital ranking .csv','a')
f.seek(2)
for item in als:
f.write('\n'+','.join(item))
f.close()
ranking , Hospital name , The reputation of the specialist , Scientific research and academic research , Comprehensive score
1, Peking Union Hospital, Chinese Academy of Medical Sciences ,80,15.396,95.396
2, West China Hospital of Sichuan University ,69.57,20,89.57
3, PLA General Hospital ,58.658,12.734,71.392
4, Zhongshan Hospital Affiliated to Fudan University ,32.254,12.032,44.286
5, Ruijin Hospital Affiliated to medical school of Shanghai Jiaotong University ,32.807,11.436,44.243
6, Tongji Hospital Affiliated to Tongji Medical College of Huazhong University of science and technology ,23.676,14.15,37.826
7, Huashan Hospital Affiliated to Fudan University ,25.232,9.415,34.647
8, The First Affiliated Hospital of Sun Yat sen University ,23.345,10.93,34.275
9, Union Hospital Affiliated to Tongji Medical College of Huazhong University of science and Technology ,19.485,14.1,33.585
10, The First Affiliated Hospital of Medical College of Zhejiang University ,17.002,14.06,31.062
11, Xijing Hospital of Air Force Military Medical University ,22.974,7.771,30.745
12, The first hospital of Peking University ,20.523,9.398,29.921
2.4 One by one processing of two-dimensional data
Using a two-layer cycle
als=[['11',' Xijing Hospital of Air Force Military Medical University ','22.974','7.771','30.745'],\
['12',' The first hospital of Peking University ','20.523','9.398','29.921']]
for row in als:
for column in row:
print(column)
11
Xijing Hospital of Air Force Military Medical University
22.974
7.771
30.745
12
The first hospital of Peking University
20.523
9.398
29.921
>>>
3、 High dimensional data
High dimensional data consists of key value pair data , Organize... In an object-oriented manner , Compared with one-dimensional and two-dimensional data, it can express more flexible and complex data relationships . This leads to HTML,XML、JSON And so on , It's today Internet The main form of organizing content .
边栏推荐
- Fast power (template)
- Manually page the list (parameter list, current page, page size)
- 【无标题】
- High performance parallel programming and optimization | lesson 02 homework at home
- [microservice] Nacos cluster building and loading file configuration
- How to implement cross domain requests
- LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
- How to expand all collapse panels
- 体验碎周报第 102 期(2022.7.4)
- [excel] PivotChart
猜你喜欢
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
How does apscheduler set tasks not to be concurrent (that is, execute the next task after the first one)?
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
JS how to convert seconds into hours, minutes and seconds display
A little understanding of GSLB (global server load balance) technology
如何避免 JVM 内存泄漏?
Grounding relay dd-1/60
Functions in C language (detailed explanation)
740. Delete and get points
How to choose the middle-aged crisis of the testing post? Stick to it or find another way out? See below
随机推荐
How much computing power does transformer have
js如何将秒转换成时分秒显示
Steady! Huawei micro certification Huawei cloud computing service practice is stable!
Notes and notes
px em rem的区别
746. Climb stairs with minimum cost
Vant --- detailed explanation and use of list component in vant
Compound nonlinear feedback control (2)
测试岗的中年危机该如何选择?是坚守还是另寻出路?且看下文
Sort list tool class, which can sort strings
C language exercises (recursion)
[excel] PivotChart
Invalid revision: 3.18.1-g262b901-dirty
分布式CAP理论
Understanding of cross domain and how to solve cross domain problems
【微服务】Nacos集群搭建以及加载文件配置
2022.7.3-----leetcode. five hundred and fifty-six
How to choose the middle-aged crisis of the testing post? Stick to it or find another way out? See below
webrtc 快速搭建 视频通话 视频会议
Inputstream/outputstream (input and output of file)