I am learnings pandas and when I try to print out my dataframe results as a table using the tabulate library, the printout is skewed.
I am using the 2023 StackOverflow Survey csv as my panda dataframe source, this file can be downloaded via this link here.
import pandas as pd
from tabulate import tabulate
stack_survey_df = pd.read_csv('/Users/username/Desktop/python/python_dev/test_files/stack_overflow_developer_survey_2023/survey_results_public.csv', index_col='ResponseId')
print(tabulate(stack_survey_df.head(10), headers='keys',tablefmt='fancy_grid'))
When I select certain columns, the printout result is formatted correctly.
a) What is causing this to happen? b) What should you do to get around this format issue?
import pandas as pd
from tabulate import tabulate
stack_survey_df = pd.read_csv('/Users/anthonyerdene/Desktop/python/python_dev/test_files/stack_overflow_developer_survey_2023/survey_results_public.csv', index_col='ResponseId')
stack_survey_df.columns = stack_survey_df.columns.str.lower()
print(tabulate(stack_survey_df[['age', 'employment']].head(10), headers='keys',tablefmt='fancy_grid'))
I tried selecting certain columns, and tabulate works as expected. However, if I try to show all columns, tabulate does not work. The table format gets skewed.