[Solved] Try to plot finance data with datetime but met error TypeError: string indices must be integers, not str

The following could be used to plot your data. The main point is that you need to specify the (rather unusual) format of the datetimes (“%Y/%m/%d/%H/%M”), such that it can be converted to a datetime object. import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv(“data/minuteData.csv”) df[“minute”] = pd.to_datetime(df[“minute”], format=”%Y/%m/%d/%H/%M”) plt.plot(df[“minute”],df[“spreadprice”], label=”spreadprice” ) plt.plot(df[“minute”],df[“bollup”], … Read more

[Solved] Get a subset of a data frame into a matrix

Given (stealing from an earlier problem today): “”” IndexID IndexDateTime IndexAttribute ColumnA ColumnB 1 2015-02-05 8 A B 1 2015-02-05 7 C D 1 2015-02-10 7 X Y “”” import pandas as pd import numpy as np df = pd.read_clipboard(parse_dates=[“IndexDateTime”]).set_index([“IndexID”, “IndexDateTime”, “IndexAttribute”]) df: ColumnA ColumnB IndexID IndexDateTime IndexAttribute 1 2015-02-05 8 A B 7 C … Read more

[Solved] why I have negative date by subtraction of two column?

@cᴏʟᴅsᴘᴇᴇᴅ explain it better: When two datetime objects are subtracted, the result is a timedelta. Depending on which date was larger, the result could be positive or negative. Also if all values in column have no times, in pandas are not shown. Patient[“Waiting”] = Patient[“Appointment”] – Patient[“Scheduled”] 2016-04-29 00:00:00 – 2016-04-29 18:38:08 For remove negative … Read more

[Solved] i have developed the program and i am facing problems in it

You can try to pivot the table. Which may give the format you require. Considering the information you gave as as ActionsOnly.csv userId,movieId,rating 18,9,3 32,204,4 49,2817,1 62,160438,4 70,667,5 73,1599,1 73,4441,3 73,4614,3.5 73,86142,4 95,4636,2 103,71,1 118,3769,4 150,4866,2 You wan to find out what user rated what movie out of 5. The userId is the index column, … Read more

[Solved] Convert pandas column with currency values like €118.5M or €60K to integers or floats [closed]

Damn, a quick google search finds: def convert_si_to_number(x): total_stars = 0 x = x.replace(‘€’, ”) if ‘k’ in x: if len(x) > 1: total_stars = float(x.replace(‘k’, ”)) * 1000 # convert k to a thousand elif ‘M’ in x: if len(x) > 1: total_stars = float(x.replace(‘M’, ”)) * 1000000 # convert M to a million … Read more

[Solved] How do I loop through a single data frame column to count how many different values there are?

you have to use df.unique(). That’s why pandas is used. You are not supposed to loop through pandas. Even for applying manipulations to the data inside dataframe you should go for df.apply(). This should get the list of unique date values as a list: df.Date.unique() In case, you want to use loop: Use df.iterrows() : … Read more

[Solved] Python Unique DF in loop [closed]

If you need to upload into csv files separately during that iteration then below code follows, If this is what your looking or else please review your question for j in range(0, 500): for k in range(1,9): try: file_name=”Result_”+str(i)+’_’+str(j)+’.csv’ df1 = url_base_1 + str(j) + url_base_2 df2 = make_dataframe(df1.format(year), int(k)) print(k) df2.to_csv(file_name,encoding=’utf-8′, index=False) except: pass … Read more