df = pd.read_csv('./part-00000-66a9d65e-cad2-4f62-af22-e9acbec50dbc.c000.csv', low_memory=False) sig_cell_volt = np.array(df.iloc[:1000, 10]) sum_volt = list(np.array(df.iloc[:1000, 6])) # print(sig_cell_volt) all_cell_vot = [] for i in sig_cell_volt: i = i[2:] cell_str = i.split('_') cell_list = [] for t in cell_str: t = float(t)/1000 cell_list.append(t) # print(len(cell_list)) all_cell_vot.append(cell_list) all_cell_vot = np.array(all_cell_vot) # x_data = torch.from_numpy(all_cell_vot) print(all_cell_vot) # sing_vol_df = pd.DataFrame(all_cell_vot) # writer = pd.ExcelWriter('vol.xlsx') # sing_vol_df.to_excel(writer,'sheet1',float_format='%.5f') df1 = pd.read_excel('vol.xlsx') col_name=df1.columns.tolist() col_name.insert(95, '总电压') df1['总电压'] = sum_volt df1.to_excel('piggy22.xlsx')
时间: 2024-04-28 21:21:40 浏览: 120
这段代码首先是在上一个代码段的基础上进行的。在处理完数据后,代码将 all_cell_vot 数组中的数据存储到了名为 sing_vol_df 的 DataFrame 中,并将这个 DataFrame 存储到了一个名为 vol.xlsx 的 Excel 文件中。
接下来,代码又读取了 vol.xlsx 文件,并将 DataFrame 中的列名存储到了名为 col_name 的列表中。然后,通过 insert 方法在 col_name 列表的索引 95 处插入了一个名为“总电压”的列名。接着,代码将 sum_volt 列表中的数据存储到了新添加的“总电压”列中。最后,通过 to_excel 方法将更新后的 DataFrame 存储到了一个名为 piggy22.xlsx 的 Excel 文件中。
相关问题
(4)编程将下面一个长字符串分割成相应的字典。 cookies = "anonymid=jy0ui55o-u6f6zd; depovince=GW; _r01_=1; JSESSIONID=abcMktGLRGjLtdhBk7OVw; ick_login=a9b557b8-8138-4e9d-8601-de7b2a633f80; _ga=GA1.2.1307141854.1562980962; _gid=GA1.2.201589596.1562980962; _c1=-100; first_login_flag=1; ln_uact=18323008898; ln_hurl=http://head.xiaonei.com/photos/0/0/men_main.gif; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106763; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106765; jebecookies=793eb32e-92c6-470d-b9d0-5f924c335d30|||||; _de=E77807CE44886E0134ABF27E72CFD74F; p=a00d65b1f779614cd242dc719e24c73e0; t=292ba8729a4151c1a357e176d8d91bff0; societyguester=292ba8729a4151c1a357e176d8d91bff0; id=969937120; xnsid=1700b2cc; ver=7.0; loginfrom=null; wp_fold=0"
可以使用以下代码将该字符串分割成字典:
```
cookies = "anonymid=jy0ui55o-u6f6zd; depovince=GW; _r01_=1; JSESSIONID=abcMktGLRGjLtdhBk7OVw; ick_login=a9b557b8-8138-4e9d-8601-de7b2a633f80; _ga=GA1.2.1307141854.1562980962; _gid=GA1.2.201589596.1562980962; _c1=-100; first_login_flag=1; ln_uact=18323008898; ln_hurl=http://head.xiaonei.com/photos/0/0/men_main.gif; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106763; jebe_key=88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106765; jebecookies=793eb32e-92c6-470d-b9d0-5f924c335d30|||||; _de=E77807CE44886E0134ABF27E72CFD74F; p=a00d65b1f779614cd242dc719e24c73e0; t=292ba8729a4151c1a357e176d8d91bff0; societyguester=292ba8729a4151c1a357e176d8d91bff0; id=969937120; xnsid=1700b2cc; ver=7.0; loginfrom=null; wp_fold=0"
cookie_dict = {}
for cookie in cookies.split('; '):
key, value = cookie.split('=')
cookie_dict[key] = value
print(cookie_dict)
```
输出:
```
{'anonymid': 'jy0ui55o-u6f6zd', 'depovince': 'GW', '_r01_': '1', 'JSESSIONID': 'abcMktGLRGjLtdhBk7OVw', 'ick_login': 'a9b557b8-8138-4e9d-8601-de7b2a633f80', '_ga': 'GA1.2.1307141854.1562980962', '_gid': 'GA1.2.201589596.1562980962', '_c1': '-100', 'first_login_flag': '1', 'ln_uact': '18323008898', 'ln_hurl': 'http://head.xiaonei.com/photos/0/0/men_main.gif', 'jebe_key': '88f1340c-592c-4dd6-a738-128a76559f45%7Cad33b3c730fcdc8df220648f0893e840%7C1562981108370%7C1%7C1562981106765', 'jebecookies': '793eb32e-92c6-470d-b9d0-5f924c335d30|||||', '_de': 'E77807CE44886E0134ABF27E72CFD74F', 'p': 'a00d65b1f779614cd242dc719e24c73e0', 't': '292ba8729a4151c1a357e176d8d91bff0', 'societyguester': '292ba8729a4151c1a357e176d8d91bff0', 'id': '969937120', 'xnsid': '1700b2cc', 'ver': '7.0', 'loginfrom': 'null', 'wp_fold': '0'}
```
Getting requirements to build wheel ... done Preparing wheel metadata ... done Collecting numpy>=1.17.0; python_version >= "3.7" (from opencv_python) Using cached https://files.pythonhosted.org/packages/97/9f/da37cc4a188a1d5d203d65ab28d6504e17594b5342e0c1dc5610ee6f4535/numpy-1.21.6-cp37-cp37m-win_amd64.whl Building wheels for collected packages: opencv-python Building wheel for opencv-python (PEP 517) ... / WARNING: Subprocess output does not appear to be encoded as cp936 \ WARNING: Subprocess output does not appear to be encoded as cp936 \ WARNING: Subprocess output does not appear to be encoded as cp936 | WARNING: Subprocess output does not appear to be encoded as cp936这是什么情况,如何解决
这是一个警告信息,可能是因为你的终端编码不是UTF-8,而是cp936。建议在执行命令前设置终端编码为UTF-8,或者在执行命令时添加 `-q` 或 `--quiet` 参数,以避免显示警告信息。
例如,在Windows终端中,可以使用以下命令设置编码为UTF-8:
```
chcp 65001
```
然后再执行你的命令即可,例如:
```
pip install opencv-python --quiet
```
阅读全文