Q: python converting url CSV to pandas for numerical and date value always gives wrong output Here is the python code which is trying to read the CSV file from alphavantage URL and converts it to pandas data frame. Multiple issues are there with this.
Before raising the issue, here is the code below. 
dailyurl = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=NSE:{}&apikey=key&outputsize=full&datatype=csv'.format(Ticker)
cols = ['timestamp', 'open', 'high', 'low', 'close','adjusted_close','volume','dividend_amount','split_coefficient']
dfdaily = pd.read_csv(dailyurl, skiprows=0, header=None,names=cols)
dfmonthly = pd.read_csv(monthlyurl, skiprows=0, header=None,names=cols)
dfdaily.rename(columns = {'timestamp':'date'}, inplace = True)
dfdaily = dfdaily.apply(pd.to_numeric, errors='coerce').fillna(0).astype(float)
dfdaily.drop(dfdaily.index[:1], inplace=True)
dfdaily = dfdaily.apply(pd.to_numeric, errors='coerce').fillna(0).astype(float)
dfdaily.reset_index(inplace=True, drop=False)
print(dfdaily.head(6))

Issues:


*

*dfdaily = pd.read_csv(dailyurl, skiprows=0, header=None,names=cols) return values seems to not match with pandas dataframe (looks like it contains a string) hence when I use this dataframe I am getting error "high is not dobule"

*This URL return value contains multi-index as below 
0           1        2      3     4

0  Timestamp    open     High   Low   close
1  09-02-2017   100      110    99    96
In the above first 0,1,2,3,4 column index not wanted hence added 
dfdaily.drop(dfdaily.index[:1], inplace=True) now ,is there a better way to get the dataframe output converting this from csv to pddataframe.


*As i see the read values are string i just tried making the dataframe as numeric value by using this line 
 dfdaily = dfdaily.apply(pd.to_numeric, errors='coerce').fillna(0).astype(float)

this converts the date value to 0.0 so lost the purpose the date should be retain as its.And with this many lines of code for converting pandasdata frame it takes lot of time,so really a better way of doing to get the desired output is needed.
The output I am getting is :
   index  date     open     high      low    close  adjusted_close     volume
0      1   0.0  1629.05  1655.00  1617.30  1639.40         1639.40   703720.0   
1      2   0.0  1654.00  1679.00  1638.05  1662.15         1662.15   750746.0   
2      3   0.0  1680.00  1687.00  1620.60  1641.65         1641.65  1466983.0   
3      4   0.0  1530.00  1683.75  1511.20  1662.15         1662.15  2109416.0   
4      5   0.0  1600.00  1627.95  1546.50  1604.95         1604.95  1472164.0   
5      6   0.0  1708.05  1713.00  1620.20  1628.90         1628.90  1645045.0 

Multiindex is not required and date shall be as date not "0"
and other open high low close shall be in numerical format.
light on this optimization , a nice code which will give pandas numerical dataframe with an index as "date" so that it can be used for arithmetic logical execution further.

A: I think you need omit parameter names, because csv has header. Also for DatetimeIndex add parameter index_col for set first column to index and parse_dates for convert it to datetimes. Last rename_axis rename timestamp to date:
dfdaily = pd.read_csv(dailyurl, index_col=[0], parse_dates=[0])
dfdaily = dfdaily.rename_axis('date')
print (dfdaily.head())
             open  high    low  close  adjusted_close   volume  \
date                                                             
2018-02-09  20.25  21.0  20.25  20.25           20.25    21700   
2018-02-08  20.50  20.5  20.25  20.50           20.50  1688900   
2018-02-07  20.50  20.5  20.25  20.50           20.50   301800   
2018-02-06  20.25  21.0  20.25  20.25           20.25    39400   
2018-02-05  20.50  21.0  20.25  20.50           20.50     5400   

            dividend_amount  split_coefficient  
date                                            
2018-02-09              0.0                1.0  
2018-02-08              0.0                1.0  
2018-02-07              0.0                1.0  
2018-02-06              0.0                1.0  
2018-02-05              0.0                1.0  


print (dfdaily.dtypes)
open                 float64
high                 float64
low                  float64
close                float64
adjusted_close       float64
volume                 int64
dividend_amount      float64
split_coefficient    float64
dtype: object

print (dfdaily.index)
DatetimeIndex(['2018-02-09', '2018-02-08', '2018-02-07', '2018-02-06',
               '2018-02-05', '2018-02-02', '2018-02-01', '2018-01-31',
               '2018-01-30', '2018-01-29',
               ...
               '2000-01-14', '2000-01-13', '2000-01-12', '2000-01-11',
               '2000-01-10', '2000-01-07', '2000-01-06', '2000-01-05',
               '2000-01-04', '2000-01-03'],
              dtype='datetime64[ns]', name='date', length=4556, freq=None)

