'Loading the data of two files as Pandas Dataframe

Load the data in the two files as Pandas Dataframe (you should use the following parameters: index_col=0, parse_dates=True). You should use a for loop and put the Dataframe to Dict object (the key of Dict is a ticker: BTC, ETH) whose name is dfs. You should begin with the following code:

tickers = ['BTC', 'ETH']
dfs = {}
for ticker in tickers:
dfs[ticker] =

My Code:

input

df = pd.read_csv('BTC.csv', 'ETH.csv', index_col=0, parse_dates=True)

output

Date,Log_ret
1-Jan-19,
2-Jan-19,0.016764241
3-Jan-19,-0.024485473
4-Jan-19,0.005960876
5-Jan-19,-0.004559779
...
17-Sep-21,-0.009790588
18-Sep-21,0.021423674
19-Sep-21,-0.022356795
20-Sep-21,-0.097027196
21-Sep-21,-0.030213521
995 rows × 0 columns

I seem to get only the data from BTC.csv file. Would I have to look into concatenate two strings to get both sets of data into the DataFrame?

Some insight/clarification on this would be super helpful. Thank you!



Solution 1:[1]

The problem in this line

df = pd.read_csv('BTC.csv', 'ETH.csv', index_col=0, parse_dates=True)

is the following: read_csv() reads one CSV file at a time. The file name should be passed as the first argument (as you do), but the rest of the arguments do different things.

You want to do the following:

df_BTC = pd.read_csv('BTC.csv', index_col=0, parse_dates=True)
df_ETH = pd.read_csv('ETH.csv', index_col=0, parse_dates=True)

In what you have written, 'ETH.csv' is not interpreted as the filename to be opened. Since it is the second argument you passed, it corresponds to read_csv()'s second parameter, i.e. sep (see the link above).
As a result, you function call, opens (only) BTC.csv, and instead of splitting cols by the delimiter string ",", it splits them by the (non-existent) delimiter "ETH.csv". So all of the data in each row are assumed to belong on the same (first) column, which is treated as an index, due to having set index_col=0.
This is why you are seeing: "995 rows × 0 columns" when examining df.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kyriakosSt