You can use the following basic syntax to convert a pandas DataFrame from a wide format to a long format: df = pd. melt(df, id_vars='col1', value_vars=['col2', 'col3', ...]) In this scenario, col1 is the column we use as an identifier and col2, col3, etc.
There's a better way. It's called PyArrow — an amazing Python binding for the Apache Arrow project. It introduces faster data read/write times and doesn't otherwise interfere with your data analysis pipeline. It's the best of both worlds, as you can still use Pandas for further calculations.
You can use the print() method to print the dataframe in a table format. You can convert the dataframe to String using the to_string() method and pass it to the print method which will print the dataframe.
You can use options.display.max_colwidth
to specify you want to see more in the default representation:
In [2]: df
Out[2]:
one
0 one
1 two
2 This is very long string very long string very...
In [3]: pd.options.display.max_colwidth
Out[3]: 50
In [4]: pd.options.display.max_colwidth = 100
In [5]: df
Out[5]:
one
0 one
1 two
2 This is very long string very long string very long string veryvery long string
And indeed, if you just want to inspect the one value, by accessing it (as a scalar, not as a row as df.iloc[2]
does) you also see the full string:
In [7]: df.iloc[2,0] # or df.loc[2,'one']
Out[7]: 'This is very long string very long string very long string veryvery long string'
Use pd.set_option('display.max_colwidth', None)
for automatic linebreaks and multi-line cells.
This is a great resource on how to use jupyters display with pandas to the fullest.
Edited:
Used to be pd.set_option('display.max_colwidth', -1)
.
Another, pretty simple approach is to call list function:
list(df['one'][2])
# output:
['This is very long string very long string very long string veryvery long string']
No worth to mention, that is not good to convent to list the whole columns, but for a simple line - why not
Another easier way to print the whole string is to call values
on the dataframe.
df = pd.DataFrame({'one' : ['one', 'two',
'This is very long string very long string very long string veryvery long string']})
print(df.values)
The Output will be
[['one']
['two']
['This is very long string very long string very long string veryvery long string']]
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