如何在熊猫数据框中创建1万条记录?

问题描述 投票:0回答:3

我已经在熊猫中创建了一个数据框,但是其中只存储了1个值。在Pandas中,有没有一种方法可以用10k条记录填充数据框?这是我创建的数据框。

from mimesis import Cryptographic
import pandas as pd
c= Cryptographic()
string = 'http://www.youtube.com/channel/'
profile_url = string + "/" + c.token_urlsafe()
df1 = pd.DataFrame({'Profile_Url':[profile_url]})
print(df1.head())

这是打印后的结果。

 Picture_URL
0  https://yt3.ggpht.com/a-/_YIp1UQhJFAyIxSn0eWvb...

我想将这些唯一的URL存储10000次,而不是将同一记录重复10000次

所以我期望有类似的东西。

Picture_URL
0  https://yt3.ggpht.com/a-/_YIp1UQhKFMyIxSn0eWvn...
0  https://yt3.ggpht.com/a-/_KIy1UQhEFAyIxSn0eWvt...
0  https://yt3.ggpht.com/a-/_WIp1UQhSFAyIxSx0eWzq...

我如何添加最多10K的行

python pandas dataframe
3个回答
0
投票

IIUC,您想在数据框中复制同一行10K次。

您可以使用np.repeat

执行此操作
np.repeat

0
投票

IIUC,import numpy as np newdf = pd.DataFrame(np.repeat(df.values,10000,axis=0))

DataFrame.reindex

如果您不使用RangeIndex,请使用:

DataFrame.reindex

如果您不希望其他列,可以将df = df.reindex(index=np.arange(10000)) 传递给df = df.reset_index().reindex(index=np.arange(10000))


0
投票

使用drop=True理解在列表理解中生成reset_index个不同的链接:

list
© www.soinside.com 2019 - 2024. All rights reserved.