Column
Bases: Sequence[T_co]
A named, one-dimensional collection of homogeneous values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the column. |
required |
data |
Sequence[T_co] | None
|
The data of the column. If None, an empty column is created. |
None
|
Examples:
>>> from safeds.data.tabular.containers import Column
>>> Column("test", [1, 2, 3])
+------+
| test |
| --- |
| i64 |
+======+
| 1 |
| 2 |
| 3 |
+------+
Source code in src/safeds/data/tabular/containers/_column.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 |
|
is_numeric: bool
¶
Whether the column is numeric.
is_temporal: bool
¶
Whether the column is operator.
name: str
¶
The name of the column.
plot: ColumnPlotter
¶
The plotter for the column.
row_count: int
¶
The number of rows in the column.
type: DataType
¶
The type of the column.
all
¶
Return whether all values in the column satisfy the predicate.
The predicate can return one of three values:
- True, if the value satisfies the predicate.
- False, if the value does not satisfy the predicate.
- None, if the truthiness of the predicate is unknown, e.g. due to missing values.
By default, cases where the truthiness of the predicate is unknown are ignored and this method returns
- True, if the predicate always returns True or None.
- False, if the predicate returns False at least once.
You can instead enable Kleene logic by setting ignore_unknown=False
. In this case, this method returns
- True, if the predicate always returns True.
- False, if the predicate returns False at least once.
- None, if the predicate never returns False, but at least once None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predicate |
Callable[[Cell[T_co]], Cell[bool | None]]
|
The predicate to apply to each value. |
required |
ignore_unknown |
bool
|
Whether to ignore cases where the truthiness of the predicate is unknown. |
True
|
Returns:
Name | Type | Description |
---|---|---|
all_satisfy_predicate |
bool | None
|
Whether all values in the column satisfy the predicate. |
Raises:
Type | Description |
---|---|
TypeError
|
If the predicate does not return a boolean cell. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.all(lambda cell: cell > 0)
True
Source code in src/safeds/data/tabular/containers/_column.py
any
¶
Return whether any value in the column satisfies the predicate.
The predicate can return one of three values:
- True, if the value satisfies the predicate.
- False, if the value does not satisfy the predicate.
- None, if the truthiness of the predicate is unknown, e.g. due to missing values.
By default, cases where the truthiness of the predicate is unknown are ignored and this method returns
- True, if the predicate returns True at least once.
- False, if the predicate always returns False or None.
You can instead enable Kleene logic by setting ignore_unknown=False
. In this case, this method returns
- True, if the predicate returns True at least once.
- False, if the predicate always returns False.
- None, if the predicate never returns True, but at least once None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predicate |
Callable[[Cell[T_co]], Cell[bool | None]]
|
The predicate to apply to each value. |
required |
ignore_unknown |
bool
|
Whether to ignore cases where the truthiness of the predicate is unknown. |
True
|
Returns:
Name | Type | Description |
---|---|---|
any_satisfy_predicate |
bool | None
|
Whether any value in the column satisfies the predicate. |
Raises:
Type | Description |
---|---|
TypeError
|
If the predicate does not return a boolean cell. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.any(lambda cell: cell > 2)
True
Source code in src/safeds/data/tabular/containers/_column.py
correlation_with
¶
Calculate the Pearson correlation between this column and another column.
The Pearson correlation is a value between -1 and 1 that indicates how much the two columns are linearly related:
- A correlation of -1 indicates a perfect negative linear relationship.
- A correlation of 0 indicates no linear relationship.
- A correlation of 1 indicates a perfect positive linear relationship.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
Column
|
The other column to calculate the correlation with. |
required |
Returns:
Name | Type | Description |
---|---|---|
correlation |
float
|
The Pearson correlation between the two columns. |
Raises:
Type | Description |
---|---|
TypeError
|
If one of the columns is not numeric. |
ValueError
|
If the columns have different lengths. |
ValueError
|
If one of the columns has missing values. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column1 = Column("test", [1, 2, 3])
>>> column2 = Column("test", [2, 4, 6])
>>> column1.correlation_with(column2)
1.0
Source code in src/safeds/data/tabular/containers/_column.py
count_if
¶
Return how many values in the column satisfy the predicate.
The predicate can return one of three results:
- True, if the value satisfies the predicate.
- False, if the value does not satisfy the predicate.
- None, if the truthiness of the predicate is unknown, e.g. due to missing values.
By default, cases where the truthiness of the predicate is unknown are ignored and this method returns how often the predicate returns True.
You can instead enable Kleene logic by setting ignore_unknown=False
. In this case, this method returns None if
the predicate returns None at least once. Otherwise, it still returns how often the predicate returns True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predicate |
Callable[[Cell[T_co]], Cell[bool | None]]
|
The predicate to apply to each value. |
required |
ignore_unknown |
bool
|
Whether to ignore cases where the truthiness of the predicate is unknown. |
True
|
Returns:
Name | Type | Description |
---|---|---|
count |
int | None
|
The number of values in the column that satisfy the predicate. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.count_if(lambda cell: cell > 1)
2
Source code in src/safeds/data/tabular/containers/_column.py
distinct_value_count
¶
Return the number of distinct values in the column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_missing_values |
bool
|
Whether to ignore missing values when counting distinct values. |
True
|
Returns:
Name | Type | Description |
---|---|---|
distinct_value_count |
int
|
The number of distinct values in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3, 2])
>>> column.distinct_value_count()
3
Source code in src/safeds/data/tabular/containers/_column.py
get_distinct_values
¶
Return the distinct values in the column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_missing_values |
bool
|
Whether to ignore missing values. |
True
|
Returns:
Name | Type | Description |
---|---|---|
distinct_values |
Sequence[T_co | None]
|
The distinct values in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3, 2])
>>> column.get_distinct_values()
[1, 2, 3]
Source code in src/safeds/data/tabular/containers/_column.py
get_value
¶
Return the column value at specified index. Equivalent to the []
operator (indexed access).
Nonnegative indices are counted from the beginning (starting at 0), negative indices from the end (starting at -1).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int
|
Index of requested value. |
required |
Returns:
Name | Type | Description |
---|---|---|
value |
T_co
|
Value at index. |
Raises:
Type | Description |
---|---|
IndexError
|
If the index is out of bounds. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.get_value(1)
2
Source code in src/safeds/data/tabular/containers/_column.py
idness
¶
Calculate the idness of this column.
We define the idness as the number of distinct values (including missing values) divided by the number of rows. If the column is empty, the idness is 1.0.
A high idness indicates that the column most values in the column are unique. In this case, you must be careful when using the column for analysis, as a model may learn a mapping from this column to the target.
Returns:
Name | Type | Description |
---|---|---|
idness |
float
|
The idness of the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column1 = Column("test", [1, 2, 3])
>>> column1.idness()
1.0
Source code in src/safeds/data/tabular/containers/_column.py
max
¶
Return the maximum value in the column.
Returns:
Name | Type | Description |
---|---|---|
max |
T_co | None
|
The maximum value in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.max()
3
Source code in src/safeds/data/tabular/containers/_column.py
mean
¶
Return the mean of the values in the column.
The mean is the sum of the values divided by the number of values.
Returns:
Name | Type | Description |
---|---|---|
mean |
T_co
|
The mean of the values in the column. |
Raises:
Type | Description |
---|---|
TypeError
|
If the column is not numeric. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.mean()
2.0
Source code in src/safeds/data/tabular/containers/_column.py
median
¶
Return the median of the values in the column.
The median is the value in the middle of the sorted list of values. If the number of values is even, the median is the mean of the two middle values.
Returns:
Name | Type | Description |
---|---|---|
median |
T_co
|
The median of the values in the column. |
Raises:
Type | Description |
---|---|
TypeError
|
If the column is not numeric. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.median()
2.0
Source code in src/safeds/data/tabular/containers/_column.py
min
¶
Return the minimum value in the column.
Returns:
Name | Type | Description |
---|---|---|
min |
T_co | None
|
The minimum value in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.min()
1
Source code in src/safeds/data/tabular/containers/_column.py
missing_value_count
¶
Return the number of missing values in the column.
Returns:
Name | Type | Description |
---|---|---|
missing_value_count |
int
|
The number of missing values in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, None, 3])
>>> column.missing_value_count()
1
Source code in src/safeds/data/tabular/containers/_column.py
missing_value_ratio
¶
Return the missing value ratio.
We define the missing value ratio as the number of missing values in the column divided by the number of rows. If the column is empty, the missing value ratio is 1.0.
A high missing value ratio indicates that the column is dominated by missing values. In this case, the column may not be useful for analysis.
Returns:
Name | Type | Description |
---|---|---|
missing_value_ratio |
float
|
The ratio of missing values in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, None, 3, None])
>>> column.missing_value_ratio()
0.5
Source code in src/safeds/data/tabular/containers/_column.py
mode
¶
Return the mode of the values in the column.
The mode is the value that appears most frequently in the column. If multiple values occur equally often, all of them are returned. The values are sorted in ascending order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_missing_values |
bool
|
Whether to ignore missing values. |
True
|
Returns:
Name | Type | Description |
---|---|---|
mode |
Sequence[T_co | None]
|
The mode of the values in the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [3, 1, 2, 1, 3])
>>> column.mode()
[1, 3]
Source code in src/safeds/data/tabular/containers/_column.py
none
¶
Return whether no value in the column satisfies the predicate.
The predicate can return one of three values:
- True, if the value satisfies the predicate.
- False, if the value does not satisfy the predicate.
- None, if the truthiness of the predicate is unknown, e.g. due to missing values.
By default, cases where the truthiness of the predicate is unknown are ignored and this method returns
- True, if the predicate always returns False or None.
- False, if the predicate returns True at least once.
You can instead enable Kleene logic by setting ignore_unknown=False
. In this case, this method returns
- True, if the predicate always returns False.
- False, if the predicate returns True at least once.
- None, if the predicate never returns True, but at least once None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predicate |
Callable[[Cell[T_co]], Cell[bool | None]]
|
The predicate to apply to each value. |
required |
ignore_unknown |
bool
|
Whether to ignore cases where the truthiness of the predicate is unknown. |
True
|
Returns:
Name | Type | Description |
---|---|---|
none_satisfy_predicate |
bool | None
|
Whether no value in the column satisfies the predicate. |
Raises:
Type | Description |
---|---|
TypeError
|
If the predicate does not return a boolean cell. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.none(lambda cell: cell < 0)
True
Source code in src/safeds/data/tabular/containers/_column.py
rename
¶
Return a new column with a new name.
Note: The original column is not modified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_name |
str
|
The new name of the column. |
required |
Returns:
Name | Type | Description |
---|---|---|
renamed_column |
Column[T_co]
|
A new column with the new name. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.rename("new_name")
+----------+
| new_name |
| --- |
| i64 |
+==========+
| 1 |
| 2 |
| 3 |
+----------+
Source code in src/safeds/data/tabular/containers/_column.py
stability
¶
Return the stability of the column.
We define the stability as the number of occurrences of the most common non-missing value divided by the total number of non-missing values. If the column is empty or all values are missing, the stability is 1.0.
A high stability indicates that the column is dominated by a single value. In this case, the column may not be useful for analysis.
Returns:
Name | Type | Description |
---|---|---|
stability |
float
|
The stability of the column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 1, 2, 3, None])
>>> column.stability()
0.5
Source code in src/safeds/data/tabular/containers/_column.py
standard_deviation
¶
Return the standard deviation of the values in the column.
The standard deviation is the square root of the variance.
Returns:
Name | Type | Description |
---|---|---|
standard_deviation |
float
|
The standard deviation of the values in the column. If no standard deviation can be calculated due to the type of the column, None is returned. |
Raises:
Type | Description |
---|---|
TypeError
|
If the column is not numeric. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.standard_deviation()
1.0
Source code in src/safeds/data/tabular/containers/_column.py
summarize_statistics
¶
Return a table with important statistics about the column.
Returns:
Name | Type | Description |
---|---|---|
statistics |
Table
|
The table with statistics. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("a", [1, 3])
>>> column.summarize_statistics()
+----------------------+---------+
| metric | a |
| --- | --- |
| str | f64 |
+================================+
| min | 1.00000 |
| max | 3.00000 |
| mean | 2.00000 |
| median | 2.00000 |
| standard deviation | 1.41421 |
| distinct value count | 2.00000 |
| idness | 1.00000 |
| missing value ratio | 0.00000 |
| stability | 0.50000 |
+----------------------+---------+
Source code in src/safeds/data/tabular/containers/_column.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
|
to_list
¶
Return the values of the column in a list.
Returns:
Name | Type | Description |
---|---|---|
values |
list[T_co]
|
The values of the column in a list. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.to_list()
[1, 2, 3]
Source code in src/safeds/data/tabular/containers/_column.py
to_table
¶
Create a table that contains only this column.
Returns:
Name | Type | Description |
---|---|---|
table |
Table
|
The table with this column. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.to_table()
+------+
| test |
| --- |
| i64 |
+======+
| 1 |
| 2 |
| 3 |
+------+
Source code in src/safeds/data/tabular/containers/_column.py
transform
¶
Return a new column with values transformed by the transformer.
Note: The original column is not modified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformer |
Callable[[Cell[T_co]], Cell[R_co]]
|
The transformer to apply to each value. |
required |
Returns:
Name | Type | Description |
---|---|---|
transformed_column |
Column[R_co]
|
A new column with transformed values. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.transform(lambda cell: 2 * cell)
+------+
| test |
| --- |
| i64 |
+======+
| 2 |
| 4 |
| 6 |
+------+
Source code in src/safeds/data/tabular/containers/_column.py
variance
¶
Return the variance of the values in the column.
The variance is the average of the squared differences from the mean.
Raises:
Type | Description |
---|---|
TypeError
|
If the column is not numeric. |
Returns:
Name | Type | Description |
---|---|---|
variance |
float
|
The variance of the values in the column. If no variance can be calculated due to the type of the column, None is returned. |
Examples:
>>> from safeds.data.tabular.containers import Column
>>> column = Column("test", [1, 2, 3])
>>> column.variance()
1.0