[英]How do process my research data with python?
For some research I am doing at school, a system I am using outputs data in the form of a list like this: 对于我在学校进行的一些研究,我正在使用一个系统,该系统以如下列表的形式输出数据:
data = [
['Original Scan', 0, 23.146309375681962, 36.534373218200166],
[5, 0.00015808600180850993, 14.03180693064792, 25.130059826146226],
['Degauss 1', 0.0001676565009807885, 18.33996552587951, 29.85652818261233],
[5, 0.00019503035220289067, 19.595745760249194, 29.495763024929236],
['Degauss 1', 0.000210060256315139, 17.858656990945203, 32.31149763207207],
[5, 0.00019177307042011343, 16.65182665346039, 26.7927902597764],
['Degauss 1', 0.00022217761737506128, 15.408535501863321, 26.37129524475812],
[5, 0.0002954777643168222, 22.794048652120257, 36.9308761639897],
['Degauss 1', 0.0003189866582346615, 14.948934127369814, 25.609259161487458],
[5, 0.0001905522028747761, 19.11779411980358, 26.93926634886425],
['Degauss 1', 0.0002596848642076495, 16.52493208221349, 36.08480345294324],
[5, 0.00022975870192903274, 15.457531404917487, 31.469277860171324],
['Degauss 1', 0.0002730733953392396, 13.59039025942238, 29.017694984805246],
[5, 0.0003324072595179313, 17.418260625360308, 39.9332167049047],
['Degauss 1', 0.00032467106202796296, 16.411012017845984, 27.238517089900547],
[5, 0.00019501569409976008, 16.434946285329566, 36.082764772986465],
['Degauss 1', 0.0001999899241164997, 13.621001825807184, 33.85443152374901],
[5, 0.0002480635909895036, 17.14186587678462, 31.212129845941686],
['Degauss 1', 0.0003010572239328449, 15.488957095845786, 30.596635683607417],
[5, 0.00024775935778942717, 14.550641342289275, 40.762954460951356],
['Degauss 1', 0.00016019323753253822, 13.847293394514374, 28.42756792202193]
]
How can I get the third element of each sub-list from this dataset, and then place it in a new list? 如何从此数据集中获取每个子列表的第三个元素,然后将其放置在新列表中?
You can use the following snip of code I always use in those cases: 在这些情况下,您可以使用以下我经常使用的代码片段:
new_list=[] #list that will contain each third value
index=2 #in your case this is 2 to get the third value
[new_list.append(colm[index]) for colm in data]
print(new_list)
Feel free to ask any questions. 随意问任何问题。
This is how it can be done in Python: 这是可以在Python中完成的方法:
Note, this does not 'remove' the items from list-1. 请注意,这不会从列表1中“删除”项目。 Do you really want to modify the first dataset?
您真的要修改第一个数据集吗?
#!/usr/bin/python3
data = [['Original Scan', 0, 23.146309375681962, 36.534373218200166],
[5, 0.00015808600180850993, 14.03180693064792, 25.130059826146226],
['Degauss 1', 0.0001676565009807885, 18.33996552587951, 29.85652818261233],
[5, 0.00019503035220289067, 19.595745760249194, 29.495763024929236],
['Degauss 1', 0.000210060256315139, 17.858656990945203, 32.31149763207207],
[5, 0.00019177307042011343, 16.65182665346039, 26.7927902597764],
['Degauss 1', 0.00022217761737506128, 15.408535501863321, 26.37129524475812],
[5, 0.0002954777643168222, 22.794048652120257, 36.9308761639897],
['Degauss 1', 0.0003189866582346615, 14.948934127369814, 25.609259161487458],
[5, 0.0001905522028747761, 19.11779411980358, 26.93926634886425],
['Degauss 1', 0.0002596848642076495, 16.52493208221349, 36.08480345294324],
[5, 0.00022975870192903274, 15.457531404917487, 31.469277860171324],
['Degauss 1', 0.0002730733953392396, 13.59039025942238, 29.017694984805246],
[5, 0.0003324072595179313, 17.418260625360308, 39.9332167049047],
['Degauss 1', 0.00032467106202796296, 16.411012017845984, 27.238517089900547],
[5, 0.00019501569409976008, 16.434946285329566, 36.082764772986465],
['Degauss 1', 0.0001999899241164997, 13.621001825807184, 33.85443152374901],
[5, 0.0002480635909895036, 17.14186587678462, 31.212129845941686],
['Degauss 1', 0.0003010572239328449, 15.488957095845786, 30.596635683607417],
[5, 0.00024775935778942717, 14.550641342289275, 40.762954460951356],
['Degauss 1', 0.00016019323753253822, 13.847293394514374, 28.42756792202193]]
List = []
for item in data:
List.append(item[2])
print(List)
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.