Function polars_core::utils::concat_df
source · pub fn concat_df<'a, I>(dfs: I) -> PolarsResult<DataFrame>where
I: IntoIterator<Item = &'a DataFrame>,Expand description
Concat the DataFrames to a single DataFrame.
Examples found in repository?
src/functions.rs (line 289)
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
pub fn diag_concat_df(dfs: &[DataFrame]) -> PolarsResult<DataFrame> {
// TODO! replace with lazy only?
let upper_bound_width = dfs.iter().map(|df| df.width()).sum();
let mut column_names = AHashSet::with_capacity(upper_bound_width);
let mut schema = Vec::with_capacity(upper_bound_width);
for df in dfs {
df.get_columns().iter().for_each(|s| {
let name = s.name();
if column_names.insert(name) {
schema.push((name, s.dtype()))
}
});
}
let dfs = dfs
.iter()
.map(|df| {
let height = df.height();
let mut columns = Vec::with_capacity(schema.len());
for (name, dtype) in &schema {
match df.column(name).ok() {
Some(s) => columns.push(s.clone()),
None => columns.push(Series::full_null(name, height, dtype)),
}
}
DataFrame::new_no_checks(columns)
})
.collect::<Vec<_>>();
concat_df(&dfs)
}