October 2019
Beginner to intermediate
674 pages
16h 43m
English
A DataFrame is an in-memory object. Often, DataFrames need to be saved as physical files for later use. In such cases, the DataFrames can be written as a CSV or TXT file.
Let's create a synthesized DataFrame using random numbers:
import numpy as npimport pandas as pda=['Male','Female']b=['Rich','Poor','Middle Class']gender=[]seb=[]for i in range(1,101): gender.append(np.random.choice(a)) seb.append(np.random.choice(b)) height=30*np.random.randn(100)+155 weight=20*np.random.randn(100)+60 age=10*np.random.randn(100)+35 income=1500*np.random.randn(100)+15000df=pd.DataFrame({'Gender':gender,'Height':height,'Weight':weight,'Age':age,'Income':income,'Socio-Eco':seb})
This can be written to a .csv or .txt file using the to_csv
Read now
Unlock full access