<jupyter_start><jupyter_text>Writing an iterator to load data in chunks (1)Another way to read data too large to store in memory in chunks is to read the file in as DataFrames of a certain length, say, 100. For example, with the pandas package (imported as pd), you can do pd.read_csv(filename, chunksize=100). This creates an iterable reader object, which means that you can use next() on it.In this exercise, you will read a file in small DataFrame chunks with read_csv(). You're going to use the World Bank Indicators data 'ind_pop.csv', available in your current directory, to look at the urban population indicator for numerous countries and years. Instructions- Use pd.read_csv() to read in 'ind_pop.csv' in chunks of size 10. Assign the result to df_reader.- Print the first two chunks from df_reader.<jupyter_code># Import the pandas package
import pandas as pd

# Initialize reader object: df_reader
df_reader = pd.read_csv('world_ind_pop_data.csv' , chunksize= 10)

# Print two chunks
print(next(df_reader))
print(next(df_reader))<jupyter_output>CountryName CountryCode  Year  \
0                                 Arab World         ARB  1960   
1                     Caribbean small states         CSS  1960   
2             Central Europe and the Baltics         CEB  1960   
3    East Asia & Pacific (all income levels)         EAS  1960   
4      East Asia & Pacific (developing only)         EAP  1960   
5                                  Euro area         EMU  1960   
6  Europe & Central Asia (all income levels)         ECS  1960   
7    Europe & Central Asia (developing only)         ECA  1960   
8                             European Union         EUU  1960   
9   Fragile and conflict affected situations         FCS  1960   

   Total Population  Urban population (% of total)  
0      9.249590e+07                      31.285384  
1      4.190810e+06                      31.597490  
2      9.140158e+07                      44.507921  
3      1.042475e+09                      22.471132  
4      8[...]
{'fraction_non_alphanumeric': 0.050788954635108484, 'fraction_numerical': 0.06656804733727811, 'mean_word_length': 2.0419790104947526, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '2600', 'license': 'MIT', 'n_tokens_mistral': 629, 'n_tokens_neox': 543, 'n_words': 242, 'path': 'Python Data Science Toolbox -Part 2/Bringing it all together/08. Writing an iterator to load data in chunks (1).ipynb', 'repo_name': 'nazmusshakib121/Python-Programming', 'size': '2028'}