我在一个数据框上运行一段代码,它有一个链接列,其中有一个指向页面的链接. 基于一些try 和错误,我意识到结果是好的,直到我达到代码的这一部分:

df1 = df[df['operator'] == 'test']
df1.reset_index(inplace=True, drop=True)
df1[phone_col] = df1['new_phone']
df.to_excel(f'step2_1.xlsx', index=False)

when I open the step2_1.xlsx, the link column goes only to index of 65531 and then after that its blank like the picture below. enter image description here how can i fix it? is it related to a setting for vscode?

推荐答案

Excel内置的超链接限制为65530.

Source 1,Source 2,Source 3.

您可以绕过此限制using the HYPERLINK function of Excel%.

因此,举个例子:

(pd.DataFrame([['test', '=HYPERLINK("https://www.google.com/")']]*65600, columns = ['Name', 'Link'])
 .to_excel(f'step2_1.xlsx', index=False))

enter image description here

编辑

这说明了如何将列中的当前字符串轻松转换为Excel超链接公式:

df = pd.DataFrame([['test', 'https://www.google.com/']]*10, columns = ['Name', 'Link'])
df['Link'] = df.Link.apply(lambda x: f'=HYPERLINK("{x}")')

输出:

    Name    Link
0   test    =HYPERLINK("https://www.google.com/")
1   test    =HYPERLINK("https://www.google.com/")
2   test    =HYPERLINK("https://www.google.com/")
3   test    =HYPERLINK("https://www.google.com/")
4   test    =HYPERLINK("https://www.google.com/")
5   test    =HYPERLINK("https://www.google.com/")
6   test    =HYPERLINK("https://www.google.com/")
7   test    =HYPERLINK("https://www.google.com/")
8   test    =HYPERLINK("https://www.google.com/")
9   test    =HYPERLINK("https://www.google.com/")

Python-3.x相关问答推荐

海象表达可以放在方括号中而不是括号中吗?

在Python中从mySQL获取多行

如何获得给定列表中所有可能的元素组合?

如何使用PySide6创建切换框架?

如何获得大Pandas 的常见时间间隔

将strid()映射到Pandas DataFrame中的字符串不会更改NaN条目,但仍然声称它们不同?

不同的焦点顺序和堆叠顺序 tkinter

如何获取实例化 `types.GenericAlias` 的下标类?

基于组/ID从原始数据框中创建两个子数据框

如何将日期时间索引写入日期类型的表?

为什么不能用格式字符串 '-' 绘制点?

Python base64.b32hexencode 未创建预期结果

将两列合并为一列,将它们制成字典 - pandas - groupby

使用正确的数据类型时,使用 Cerberus 验证 JSON 架构会引发错误

合并两个numpy数组

逗号分隔列表的 argparse 操作或类型

创建一个可旋转的 3D 地球

判断对 python 3 支持的要求

创建日志(log)文件

__cause__ 和 __context__ 有什么区别?