Python Forum
Python & Dataframe basic question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python & Dataframe basic question
Hey one quick and very easy questions for all of you I am sure haha! Related to pandas & dataframes

So basically I just have to create a dataframe that contains the GDP Data from an already imported panda library. There is a dictionary under the word "links" containing the csv file with the data. The actual question is the following

" The dictionary links contain the CSV files with all the data. The value for the key GDP is the file that contains the GDP data. The value for the key unemployment contains the unemployment data.

In [44]:
[i] links={'GDP':'',\'unemployment':''

Question 1: Create a dataframe that contains the GDP data and display the first five rows of the dataframe.
Use the dictionary links and the function pd.read_csv to create a Pandas dataframes that contains the GDP data.
Hint: links["GDP"] contains the path or name of the file.

In [52]:[python]links={'GDP':''}
links_frame=pd.DataFrame(links, index=[0])

Writing [52] gives me the following errors:

What am I doing wrong?!! I am sure it is very simple but as I am very new to this I would appreciate your help!!!! Thank you all Smile Smile Smile

ValueError Traceback (most recent call last)
<ipython-input-52-336712d33cbe> in <module>
2 links_frame=pd.DataFrame(links, index=[0])
3 path_csv=links
----> 4 df=pd.read_csv(path_csv)

/opt/conda/envs/Python36/lib/python3.6/site-packages/pandas/io/ in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
700 skip_blank_lines=skip_blank_lines)
--> 702 return _read(filepath_or_buffer, kwds)
704 parser_f.__name__ = name

/opt/conda/envs/Python36/lib/python3.6/site-packages/pandas/io/ in _read(filepath_or_buffer, kwds)
411 compression = _infer_compression(filepath_or_buffer, compression)
412 filepath_or_buffer, _, compression, should_close = get_filepath_or_buffer(
--> 413 filepath_or_buffer, encoding, compression)
414 kwds['compression'] = compression

/opt/conda/envs/Python36/lib/python3.6/site-packages/pandas/io/ in get_filepath_or_buffer(filepath_or_buffer, encoding, compression, mode)
230 if not is_file_like(filepath_or_buffer):
231 msg = "Invalid file path or buffer object type: {_type}"
--> 232 raise ValueError(msg.format(_type=type(filepath_or_buffer)))
234 return filepath_or_buffer, None, compression, False

ValueError: Invalid file path or buffer object type: <class 'dict'>

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple pandas dataframe question popohoma 1 1,098 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  Newbie question to return only the index of a dataframe zydjohn 0 1,117 Jan-22-2018, 03:40 PM
Last Post: zydjohn
  Question for dataframe to replace INF value zydjohn 0 3,768 Jan-15-2018, 10:00 PM
Last Post: zydjohn
  very simple dataframe question really_this_dumb 0 986 Jan-02-2018, 11:30 AM
Last Post: really_this_dumb
  Newbie question: how to generate dataframe and use multiple regression zydjohn 0 1,062 Dec-10-2017, 09:49 AM
Last Post: zydjohn
  Basic Question sitingbull25 2 1,711 Jul-26-2017, 04:07 PM
Last Post: sitingbull25
  pd.DataFrame question smw10c 2 2,342 Mar-30-2017, 09:12 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020