Question

I have loaded a csv file in Python, but I do not know how to look at my data without having to call specific lines/columns.

I just want to look at the data as if it was an excel file, that is being able to scroll along different rows, change manually some values, etc.

In R there is the edit function, in Stata there is the data editor. Is there something similar in Python? I use the canopy distribution.

Thanks!

Was it helpful?

Solution

Do you use a pandas dataframe? It provides some functionality to load / write csvs easily and to display their content, like .dataframe.head(10) - which displays the first ten rows. dataframe.describe() will emit useful information about your data.

If you want to try out a df you should use the following command before printing the df:

import pandas as pd
pd.set_option('display.max_columns', None)

Otherwise pandas won't print a wide dataframe, but only the columns, which can be quite confusing.

Personally, if I have to look at very big dataframes, I tend to export them to csv and look at them in Excel. It's not the best workflow, but the displaying capabillities of python are not the best. Alternatively, you can export a pandas dataframe easily to html, which might be more convienient.

Here is my saving function:

def save_file(df, file_name):
    """
    saves to a csv file in the german excel format, e.g. colon seperated
    :rtype : None
    :param df: the dataframe to be saved
    :param file_name: the filename
    """
    assert isinstance(df, DataFrame)
    df.to_csv(file_name, sep=";")

I use this small function because Excel in germany uses a colon (;) as seperator. I always forget that when using the default function of pandas and then I have to redo it...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top