1

I'm new to python and i want to get output in this form plz :

enter image description here

Instead of this

enter image description here

My code

import investpy as inv
import pandas as pd
import numpy as np

funds = ["Pluvalca Allcaps A", "Moneta Multi Caps C", "Renaissance Europe I"]
dfs = pd.DataFrame()

for fund in funds:
    df = investpy.get_fund_recent_data(fund=fund, country='france') 
    dfs = dfs.append(df.Close[-1:],ignore_index = True)
dfs = dfs.T
dfs.columns = funds
dff = np.transpose(dfs)
dfs.head()
dff.head()
Tayko
  • 11
  • 1
  • Hi, welcome to the StackOverflow community. Please see this question to ask questions more and more effectively. Tell us more about what you want and what errors you get, and where you stuck? https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Iman Shafiei Apr 26 '21 at 10:31
  • You made a mistake in calling `investpy` function. You must use alias `inv` instead of `investpy`. `df = inv.get_fund_recent_data(fund=fund, country='france')` – Zalak Bhalani Apr 26 '21 at 10:34
  • Thank you Zalak i got this message error ValueError: Length mismatch: Expected axis has 3 elements, new values have 2 elements – Tayko Apr 27 '21 at 11:13
  • Thank you Iman, i what i want is given by the 1st image. – Tayko Apr 27 '21 at 11:26

1 Answers1

0

You can do following modification when creating dff.

import investpy as inv
import pandas as pd
import numpy as np

funds = ["Pluvalca Allcaps A", "Moneta Multi Caps C", "Renaissance Europe I"]
dfs = pd.DataFrame()

for fund in funds:
    df = inv.get_fund_recent_data(fund=fund, country='france') 
    dfs = dfs.append(df.Close[-1:], ignore_index=True)
dfs = dfs.T
dfs.columns = funds
dff = np.transpose(dfs)
date1 = dff.columns[0]
dff["Date"] = date1
dff.columns = ["Close", "Date"]
dff.head()
Zalak Bhalani
  • 979
  • 7
  • 15