从 KB 转换为 bit
Convert from KB to bit
我的 csv 文件包含这样的 KB 值
8.0703125
7.401367188
8.96875
8.17578125
7.552734375
7.301757813
8.1015625
7.692382813
8.221679688
8.052734375
7.854492188
7.548828125
如何将这些值转换为位?
您可以从 .csv
文件中读取并转换为浮点数,然后转换为 bits
,如下所示:
import csv
with open("Book1.csv") as fp:
reader = csv.reader(fp)
next(reader, None) # skip the headers
data_read = [row[0] for row in reader]
def KB_to_bits(x):
# return x*8000
return round(x*8000,2)
list(map(KB_to_bits,(map(float,data_read))))
输出:
[64562.5,
59210.94,
71750.0,
65406.25,
60421.88,
58414.06,
64812.5,
61539.06,
65773.44,
64421.88,
62835.94,
60390.62]
或者您可以像下面这样使用 pandas
:
import pandas as pd
df = pd.read_csv('Book1.csv', header=None)
def KB_to_bits(x):
# return x*8000
return round(x*8000,2)
df.apply(KB_to_bits)
输出:
0
0 64562.50
1 59210.94
...
11 60390.62
我的 csv 文件包含这样的 KB 值
8.0703125
7.401367188
8.96875
8.17578125
7.552734375
7.301757813
8.1015625
7.692382813
8.221679688
8.052734375
7.854492188
7.548828125
如何将这些值转换为位?
您可以从 .csv
文件中读取并转换为浮点数,然后转换为 bits
,如下所示:
import csv
with open("Book1.csv") as fp:
reader = csv.reader(fp)
next(reader, None) # skip the headers
data_read = [row[0] for row in reader]
def KB_to_bits(x):
# return x*8000
return round(x*8000,2)
list(map(KB_to_bits,(map(float,data_read))))
输出:
[64562.5,
59210.94,
71750.0,
65406.25,
60421.88,
58414.06,
64812.5,
61539.06,
65773.44,
64421.88,
62835.94,
60390.62]
或者您可以像下面这样使用 pandas
:
import pandas as pd
df = pd.read_csv('Book1.csv', header=None)
def KB_to_bits(x):
# return x*8000
return round(x*8000,2)
df.apply(KB_to_bits)
输出:
0
0 64562.50
1 59210.94
...
11 60390.62