[英]extracting data from numpy array in python3
I imported my csv
file into a python using numpy.txt
and the results look like this: 我使用
numpy.txt
将我的csv
文件导入到python中,结果如下所示:
>>> print(FH)
array([['Probe_Name', '', 'A2M', ..., 'POS_D', 'POS_E', 'POS_F'],
['Accession', '', 'NM_000014.4', ..., 'ERCC_00092.1',
'ERCC_00035.1', 'ERCC_00034.1'],
['Class_Name', '', 'Endogenous', ..., 'Positive', 'Positive',
'Positive'],
...,
['CF33294_10', '', '6351', ..., '1187', '226', '84'],
['CF33299_11', '', '5239', ..., '932', '138', '64'],
['CF33300_12', '', '37372', ..., '981', '202', '58']], dtype=object)
every single list is a column and the first item of every column is the header. 每个列表都是一列,每列的第一项是标题。 I want to plot the data in different ways.
我想以不同的方式绘制数据。 to do so, I want to make variable for every single column.
要这样做,我想为每一列创建变量。 for example the first column I want to
print(Probe_Name)
as the header and the results will be shown like this: 例如,我要
print(Probe_Name)
的第一列print(Probe_Name)
作为标题,结果将如下所示:
A2M
.
.
.
POS_D
POS_E
POS_F
and this is the case for the rest of columns. 这是其余列的情况。 and then I will plot the variables.
然后我将绘制变量。 I tried to do that in python3 like this:
我尝试在python3中这样做:
def items(N_array:)
for item in N_array:
name = item[0]
content = item[1:]
return name, content
print(items(FH))
it does not return what I expect. print(items(FH))
它没有返回我的期望。 do you know how to fix it? 你知道怎么解决吗?
One simple way to do this is with pandas dataframes. 一种简单的方法是使用pandas数据帧。 When you read the csv file using a pandas dataframe, you essentially get a collection of 'columns' (called series in pandas).
当您使用pandas数据帧读取csv文件时,您基本上会得到一个“列”集合(在pandas中称为系列)。
import pandas as pd
df = pd.read_csv("your filename.csv")
df
Probe_Name Accession
0 A2m MD_9999
1 POS_D NM_0014.4
2 POS_E 99999
Now we can deal with each column, which is named automatically by the header column. 现在我们可以处理每个列,它由标题列自动命名。
print(df['Probe_Name'])
0 A2m
1 POS_D
2 POS_E
Furthermore, you can you do plotting (assuming you have numeric data in here somewhere). 此外,你可以做绘图(假设你在这里有数字数据)。
http://pandas.pydata.org/pandas-docs/stable/index.html http://pandas.pydata.org/pandas-docs/stable/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.