I know how to use separator (sep ="") when importing the dataset using pd.read_csv
but I don't know what to use to implement the separator on a dataset loaded from sklearn itself, like the digits dataset i used below where i want to implement the \n separator.
code:
from sklearn.datasets import load_digits
import pandas as pd
df = load_digits()
print(df)
CodePudding user response:
If you look at carefully, you'll see that load_digits
is a dictionary. You can reach its elements by
df.keys()
which returns
dict_keys(['data', 'target', 'frame', 'feature_names', 'target_names', 'images', 'DESCR'])
So, if you want to get the data, just call the data
key
df['data']
returns
[[ 0. 0. 5. ... 0. 0. 0.]
[ 0. 0. 0. ... 10. 0. 0.]
[ 0. 0. 0. ... 16. 9. 0.]
...
[ 0. 0. 1. ... 6. 0. 0.]
[ 0. 0. 2. ... 12. 0. 0.]
[ 0. 0. 10. ... 12. 1. 0.]]