I have this dataframe (compressed):
year month name
2000 January car
2000 January bike
2000 February train
2000 May car
2001 January bike
2001 February car
2001 February bike
2001 July car
2002 January car
2002 February train
2002 March bike
2002 July car
I need to add the data for 2001 and February to a list, for this I have made the following code.
name2001 = []
for year in df['year']:
if year == 2001:
for month in df['month']:
if month == 'February':
for name in df['name']:
name2001.append(name)
I was debugging and I got this error:
'Too large to show contents. Max items to show: 300'
I changed it to 10000 and I get this error:
'Too large to show contents. Max items to show: 10000'
But I know that approximately 5000 data must be added.
What is wrong with the for-loop?
question from:
https://stackoverflow.com/questions/65617553/i-have-a-problem-with-a-for-how-can-i-loop-through-the-for-and-add-the-data-to 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…