input_data_ndarray = np.array(
[['chicken', 'creamofchickensoup'], ['Chicken', 'CreamofChickensoup'], ['chicken', 'creamofchickensoup']])
result = pd.Series(input_data_ndarray).apply(lambda x: tuple(sorted(x))).nunique()
For the above code, throws
raise Exception("Data must be 1-dimensional")
E Exception: Data must be 1-dimensional
Any idea about this issue?
This could help:
In [1959]: pd.Series(input_data_ndarray.tolist())
Out[1959]:
0 [chicken, creamofchickensoup]
1 [Chicken, CreamofChickensoup]
2 [chicken, creamofchickensoup]
dtype: object
OR if you want a dataframe
, do this:
In [1960]: pd.DataFrame(input_data_ndarray)
Out[1960]:
0 1
0 chicken creamofchickensoup
1 Chicken CreamofChickensoup
2 chicken creamofchickensoup
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.