我想在pandas表中插入一个链接(到一个网页),所以当它在ipython笔记本中显示时,我可以按链接.
我尝试了以下方法:
In [1]: import pandas as pd
In [2]: df = pd.DataFrame(range(5), columns=['a'])
In [3]: df['b'] = df['a'].apply(lambda x: 'http://example.com/{0}'.format(x))
In [4]: df
Out[4]:
a b
0 0 http://example.com/0
1 1 http://example.com/1
2 2 http://example.com/2
3 3 http://example.com/3
4 4 http://example.com/4
Run Code Online (Sandbox Code Playgroud)
但是网址只显示为文字.
我也尝试过使用ipython HTML对象:
In [5]: from IPython.display import HTML
In [6]: df['b'] = df['a'].apply(lambda x:HTML('http://example.com/{0}'.format(x)))
In [7]: df
Out[7]:
a b
0 0 <IPython.core.display.HTML object at 0x0481E530>
1 1 <IPython.core.display.HTML object at 0x0481E770>
2 2 <IPython.core.display.HTML object at …Run Code Online (Sandbox Code Playgroud) 据我所知,大熊猫确实切断了长元素.但是,为什么在html输出中这样做呢?
import pandas as pd
df = pd.DataFrame(columns=['url'], index=[0])
df['url'] = 'd12dn1928d1n298dn18d9n219d8n18n118219d8n21e12903e21kj9012j9301j2391023j209d12dn1928d1n298dn18d9n219d8n18n118219d8n21e12903e21kj9012j9301j2391023j209d12dn1928d1n298dn18d9n219d8n18n118219d8n21e12903e21kj9012j9301j2391023j209d12dn1928d1n298dn18d9n219d8n18n118219d8n21e12903e21kj9012j9301j2391023j209d12dn1928d1n298dn18d9n219d8n18n118219d8n21e12903e21kj9012j9301j2391023j209'
In [2]: df
Out[2]:
url
0 d12dn1928d1n298dn18d9n219d8n18n118219d8n21e129...
In [3]: df.to_html()
Out[3]: u'<table border="1" class="dataframe">\n <thead>\n <tr style="text-align: right;">\n <th></th>\n <th>url</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>d12dn1928d1n298dn18d9n219d8n18n118219d8n21e129...</td>\n </tr>\n </tbody>\n</table>'
Run Code Online (Sandbox Code Playgroud)
即使在html输出中(显然它不适合屏幕宽度),列值也会被截断.pandas无论是否使用html,我如何强制不截断?
我找不到一个选项列表pandas.set_option().
有谁知道这样的清单是否存在?
我能找到的最好的是这个页面:http://pandas.pydata.org/pandas-docs/dev/whatsnew.html
我将链接嵌入到Pandas数据框的一列(下表)中,并将该数据框写入hmtl。
数据框表中的链接的格式如下所示(索引表中的第一个链接):
In: table.loc[0,'Links']
Out: u'<a href="http://xxx.xx.xxx.xxx/browser/I6.html">I6</a>'
Run Code Online (Sandbox Code Playgroud)
如果我查看(而不是索引特定的行)数据框(在笔记本中),则链接文本将被截断:
<a href="http://xxx.xx.xxx.xxx/browser/I6.html...
Run Code Online (Sandbox Code Playgroud)
我将数据框写入html:
table_1=table.to_html(classes='table',index=False,escape=False)
Run Code Online (Sandbox Code Playgroud)
但是,截断的链接(而不是全文)被写入html表:
<td> <a href="http://xxx.xx.xxx.xxx/browser/I6.html...</td>\n
Run Code Online (Sandbox Code Playgroud)
我可能需要to_html()的附加参数。
现在查看文档,但建议:
http://pandas.pydata.org/pandas-docs/dev/generated/pandas.DataFrame.to_html.html
谢谢!
问题:我正在尝试在 python 中使用 Pandas 数据帧存储大数据集。我的问题是,当我尝试将其保存到 csv 时,我的数据块被截断,如下所示:
e+12
和
[值1 值2 值3 。。。值1853 值1854]
说明: 我需要将大量数据存储到单个单元格中,并且我需要存储的一些值是长(时间)值,我创建了一个简短的脚本来显示我收到的错误:
dframe = pd.DataFrame()
arr = np.array([])
for x in range(1234567891230,1234567892230):
arr = np.append(arr,x)
dframe['elements'] = [arr]
print(dframe['elements'][0][999]) # prints correct values, eg. 1234567892229.0
dframe.to_csv('temp.csv', index=False)
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,前 1000 个值的存储值如下所示(123456789 1230到 123456789 2230)
1.23456789e+12
这完全忽略了四个最不重要的字符。如果将列表扩展到 1001 个值,更多值会被截断:
dframe = pd.DataFrame()
arr = np.array([])
for x in range(1234567891230,1234567892231):
arr = np.append(arr,x)
dframe['elements'] = [arr]
print(dframe['elements'][0][999]) # still prints correct values, …Run Code Online (Sandbox Code Playgroud) 我有一个包含两列的 Pandas 数据框 - 一列用于 id,另一列用于相应的标题。我正在为几个项目 ID 子集数据框并显示结果数据框。这样做时,项目 id 显示正常,但相应的标题被截断并...以几个字符结束,如何让 Pandas 在标题列中显示全文?