我已经在熊猫中创建了一个数据框,但是其中只存储了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的行
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))
使用drop=True
理解在列表理解中生成reset_index
个不同的链接:
list