数据框填充-我遇到语法错误

时间:2019-12-26 09:42:38

标签: python dataframe

对于范围(3)中的i:     vil2.loc [i] =([random.choice(['Mumbai','Delhi','Pune','Bangalore','Jaipur']))+
                [random.choice(['20-25','35-40','40-45','25-30','30-35']))+
                [random.choice(['M','F','T']))]
                [random.choice(['400012','110007','411025','560010','302021'])] +
                [[random.choice(['2-4个月','6-8个月','8-10个月','10 -12个月'])] +
                [[random.choice(['Prepaid','Postpaid']))+
                [[random.choice(['301-500','501-750','751-1000','1001-1500','201-250']))+
                [[random.choice(['7.5GB-10GB','10GB-15GB','> 15GB','10GB-15GB','2.5GB-5GB'])] +
                [[random.choice(['201-500','501-1000','> 1000']))] +
                [[random.choice(['501-750','751-1000','> 1000','250-300'])] +
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No']))] +
                [[random.choice([['金融服务“,'银行服务','娱乐','食物'])] +
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No','NA']])+
                [[random.choice(['200-250','100-150','NA']))]
                [[random.choice(['5','3','NA']])] +
                [[random.choice(['Payment Banking','Wallet','NA']))+
                [[random.choice(['Yes','No','NA']])+
                [[random.choice(['NA','300-350','> 1000']))]
                [[random.choice(['NA','2','1']))] +
                [[random.choice(['Payment Banking','Wallet','NA']))+
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Yes','No']))] +
                [[random.choice([[Live TV],'Movies','Shows'])] +
                [[random.choice([[Action],'Comedy','Drama']))+
                [[random.choice(['Hindi','English']))] +
                [[random.choice(['NA','2500','5000','7000','NA']))+
                [[random.choice(['Yes','No']))] +
                [[random.choice(['Idea','Vodafone'])])

1 个答案:

答案 0 :(得分:0)

import random

for i in range(vil2.shape[0], vil2.shape[0] + 10000):
    vil2.loc[i]= ([random.choice(['Mumbai','Delhi','Pune','Bangalore','Jaipur'])] +   
            [random.choice(['20-25','35-40','40-45','25-30','30-35'])] +   
            [random.choice(['M','F','T'])] +    
            [random.choice(['400012', '110007', '411025', '560010', '302021'])] +   
            [random.choice(['2-4 Months', '6-8 Months', '8-10 Months', '10-12 Months'])] +   
            [random.choice(['Prepaid', 'Postpaid'])] +   
            [random.choice(['301-500', '501-750', '751-1000', '1001-1500', '201-250'])] +   
            [random.choice(['7.5GB-10GB', '10GB-15GB', '>15GB', '10GB-15GB', '2.5GB-5GB'])] +   
            [random.choice(['201-500', '501-1000', '>1000'])] +   
            [random.choice(['501-750', '751-1000', '>1000', '250-300'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Finanical Services', 'Banking Services', 'Entertainment', 'Food'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No', 'NA'])] +   
            [random.choice(['200-250', '100-150', 'NA'])] +   
            [random.choice(['5', '3', 'NA'])] +   
            [random.choice(['Payment Banking', 'Wallet', 'NA'])] +   
            [random.choice(['Yes', 'No', 'NA'])] +   
            [random.choice(['NA', '300-350', '>1000'])] +   
            [random.choice(['NA', '2', '1'])] +   
            [random.choice(['Payment Banking', 'Wallet', 'NA'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Live TV', 'Movies', 'Shows'])] +  
            [random.choice(['Action', 'Comedy', 'Drama'])] +   
            [random.choice(['Hindi', 'English'])] +    
            [random.choice(['NA', '2500', '5000', '7000', 'NA'])] +   
            [random.choice(['Yes', 'No'])] +   
            [random.choice(['Idea', 'Vodafone'])] )