Попробуйте использовать API фрейма данных pandas для прямой записи файла.
df = bidirectional_different_SAB.to_data_frame()
df.to_csv("Display bidirectional relationships having different SAB.csv")
Если вы хотите формат repr
, вы можете изменить параметры pandas, используя set_option
, прежде чем запускать остальныеcode.
import pandas as pd
pd.set_option('display.width', 30000)
pd.set_option('display.max_columns', 1000)
pd.set_option('display.max_colwidth', 1000)
В качестве третьего варианта вы можете преобразовать фрейм данных в строку, заполнить его фиксированной шириной для каждого столбца, а затем сохранить фрейм даты в файл с помощью API pandas.
import pandas as pd
def get_colwidth(col):
w_header = len(col.name) if col.name else 0
w_col = col.astype(str).str.len().max()
return max(w_header, w_col)
def to_fixed_width(df):
df_out = df.astype(str)
for c in df_out:
col = df_out[c]
width = get_width(col)
df_out[c] = col
# convert the index to str as well
ix = df_out.index
df_out = df_out.set_index(ix.str.rjust(get_width(ix)))
return df_out
df = bidirectional_different_SAB.to_data_frame()
df2 = to_fixedwidth(df)
# this uses the CSV writer to write the fixed width text file with a space as the separator
df2.to_csv("Display bidirectional relationships having different SAB.txt", sep=' ')