pandas_series
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
pandas_series [2024/02/05 03:53] – [append element to series] raju | pandas_series [2024/02/06 05:11] – [dummy] raju | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Creating a series ===== | ||
+ | ==== Create a series from a list ==== | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | 0 sun | ||
+ | 1 mon | ||
+ | 2 tue | ||
+ | dtype: object | ||
+ | </ | ||
+ | |||
+ | To assign an index | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | s sun | ||
+ | m mon | ||
+ | t tue | ||
+ | dtype: object | ||
+ | </ | ||
+ | |||
+ | To assign a name to the column | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | s sun | ||
+ | m mon | ||
+ | t tue | ||
+ | Name: day, dtype: object | ||
+ | </ | ||
+ | |||
+ | To assign a name to the index | ||
+ | < | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | letter | ||
+ | s sun | ||
+ | m mon | ||
+ | t tue | ||
+ | Name: day, dtype: object | ||
+ | </ | ||
+ | |||
+ | Column name is useful when converting the series to dataframe. | ||
+ | < | ||
+ | >>> | ||
+ | 0 | ||
+ | s sun | ||
+ | m mon | ||
+ | t tue | ||
+ | |||
+ | >>> | ||
+ | day | ||
+ | s sun | ||
+ | m mon | ||
+ | t tue | ||
+ | </ | ||
+ | |||
+ | If the series did not have a name to begin with but we desire to have one while converting to the dataframe | ||
+ | < | ||
+ | >>> | ||
+ | days | ||
+ | s sun | ||
+ | m mon | ||
+ | t tue | ||
+ | </ | ||
+ | |||
+ | The index name comes in handy while resetting the index | ||
+ | < | ||
+ | >>> | ||
+ | index day | ||
+ | 0 | ||
+ | 1 | ||
+ | 2 | ||
+ | >>> | ||
+ | letter | ||
+ | 0 s sun | ||
+ | 1 m mon | ||
+ | 2 t tue | ||
+ | </ | ||
+ | |||
===== dummy ===== | ===== dummy ===== | ||
==== append element to series ==== | ==== append element to series ==== |
pandas_series.txt · Last modified: 2024/02/06 05:18 by raju