I have a dataframe extracted from Kaggle's San Fransico Salaries: https://www.kaggle.com/kaggle/sf-salaries and I wish to create a set of the values of a column, for instance 'Status'.
This is what I have tried but it brings a list of all the records instead of the set (sf is how I name the data frame).
a=set(sf['Status']) print a
According to this webpage, this should work. How to construct a set out of list items in python?
You can create a DataFrame from multiple Series objects by adding each series as a columns. By using concat() method you can merge multiple series together into DataFrame.
to_frame() function is used to convert the given series object to a dataframe. Parameter : name : The passed name should substitute for the series name (if it has one). Example #1: Use Series.
How to use the tolist() method to convert pandas series to list. To convert a pandas Series to a list, simply call the tolist() method on the series which you wish to convert.
You can create a series by calling pandas. Series() . An list, numpy array, dict can be turned into a pandas series. You should use the simplest data structure that meets your needs.
If you only need to get list of unique values, you can just use unique
method. If you want to have Python's set, then do set(some_series)
In [1]: s = pd.Series([1, 2, 3, 1, 1, 4]) In [2]: s.unique() Out[2]: array([1, 2, 3, 4]) In [3]: set(s) Out[3]: {1, 2, 3, 4}
However, if you have DataFrame, just select series out of it ( some_data_frame['<col_name>']
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With