[英]Getting columns from .json file
So I have to do some data analysis on a data-set. 因此,我必须对数据集进行一些数据分析。 The data is handed to me as a .json file.
数据作为.json文件发送给我。 (I am using Pandas to handle the data)
(我正在使用Pandas处理数据)
"columns":["id","timestamp","offset_freq","reprate_freq"]
"index":[0,1,2,3,4 ... ]
I want to be able to handle the data as regular vectors like so. 我希望能够像这样将数据作为常规向量进行处理。
id = [ ... ]
timestamp = [ ... ]
offset_freq = [ ... ]
reprate_freq = [ ... ]
But if I import my .json file with. 但是,如果我导入我的.json文件。
data=pd.read_json("comb_201601.json", orient='split')
And print one of the columns I get: 并打印出我得到的一列:
print(data['offset_freq'])
0 20000000.495
1 19999998.966
2 20000000.910
3 19999998.539
4 20000000.887
5 19999999.694
...
680204 20000000.024
Name: offset_freq, dtype: float64
What can I do to just get 我该怎么办才能得到
print(data['offset_freq'])
20000000.495
19999998.966
20000000.910
19999998.539
20000000.887
19999999.694
...
20000000.024
So data['offset_freq']
returns a pandas Series
. 因此
data['offset_freq']
返回一个熊猫Series
。
If you would like to convert that to a Python list, you can follow this example. 如果要将其转换为Python列表,则可以遵循此示例。
>>> import pandas as pd
>>> s = pd.Series([4, 5, 6])
>>> s
0 4
1 5
2 6
dtype: int64
>>> s.tolist()
[1, 2, 3]
ie You'll want 即你会想要
data['offset_freq'].tolist()
for a Python list data['offset_freq'].tolist()
用于Python列表
or 要么
data['offset_freq'].values
for a Numpy array. Numpy数组的
data['offset_freq'].values
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.