Skip to content

Read/Write Files

Read

Reading files from disk is handled with the function read_data(). The function accepts various formats, including csv, xlsx, txt, dta, Rdata, rds, sav and others. The function accepts relative paths.

Loading data
1
2
3
4
import tidypolars4sci as tp

fn = "../../src/data/example.csv"
df = tp.read_data(fn=fn)
Loading data 'example.csv'... done!
df.head().print()
shape: (3, 2)
┌───────────┐
   a     b 
 i64   i64 
╞═══════════╡
   1     4 
   2     5 
   3     6 
└───────────┘

When files type that contain labels of variables and values are loaded, the function returns a tuple with the data (tibble) and the lables (dictionary).