I am facing an issue here. I have a Dataframe column whose values I need to put as value+% i.e. say 10%, 15% etc.
However, I am able to put the values as string type in the excel sheet after writing but while I plot the graph, the value is being considered as a string and hence the chart is not getting generated.
I need to paste the value with the % symbol in the concerned column as well as I need to plot the graph while writing to the excel sheet.
Any solution for this??
Thanks in advance.
For writing the value in excel you can use
str(value) + '%'
While plotting graph access the values by slicing the last character(%) and convert it to number by using eval function.
eval(value[:-1])
Related
I am trying to read a value from a cell which is located in a subcolumn of a big column. I want to read it by using the string labels and not the integers.
How can I access the value '%' of Product1 in 'Step1' using df.loc?
I am trying
df.loc['Step1', 'Product1','%']
but it doesnt function. Thank you for your help
This is the code I'm using and I have also tried converting my datatype of my columns which is object to float but I got this error
df = pd.read_csv('DDOSping.csv')
pearsoncorr = df.corr(method='pearson')
ValueError: could not convert string to float:
'172.27.224.251-172.27.224.250-56003-502-6'
Somewhere in your CSV this string value exists '172.27.224.251-172.27.224.250-56003-502-6'. Do you know why it's there? What does it represent? It looks to me like it shouldn't be in the data you include in your correlation matrix calculation.
The df.corr method is trying to convert the string value to a float, but it's obviously not possible to do because it's a big complicated string with various characters, not a regular number.
You should clean your CSV of unnecessary data (or make a copy and clean that so you don't lose anything important). Remove anything, like metadata, that isn't the exact data that df.corr needs, including the string in the error message.
If it's just a few values you need to clean then just open in excel or a text editor to do the cleaning. If it's a lot and all the irrelevant data to be removed is in specific rows and/or columns, you could just remove them from your DataFrame before calling 'df.corr' instead of cleaning the file itself.
Cant figure out a way to extract Invoice Number as it is instead of its exponential value from an excel sheet in python.
Expected Value : 8000030910
Result: 8.00002e+09
Python Result
Excel sheet
d1.append(sheet.cell_value(j,0))
This code shows the value in exponential format.
I have extracted excel into python using xlrd.
Try wrapping the value in the int() constructor, e. g. int(8000030910). In Python 3 integers do not have the length limit, so it will be just an integer, without any exponentials.
I have a cell range temp == A23:C23 that I wanted to check if it is a subset of another.
The function issubset() can check whether one cell range is a subset of another.
My problem is that my other range is a string literal ie. 'A7:J22', so temp.issubset('A7:J22') does not work.
Is there a way that I can convert 'A7:J22' into a cell Range obj? Or another way of knowing whether my temp is a subset of this?
I can get all the valid addresses from 'A7:J22' put them in a list, then do the same with temp. But for a worksheet of over half a million cells, THAT'S A LOT!
Also tried manual comparison, ie evaluating the col and row values against the other. But that's manual. Hoping to find a more appropriate approach.
Hi hoping someone can help. I have a data frame where one of the columns contains a list of names. These names are repeated in some circumstances but not all. I am trying to plot a graph where the x-axis contains the name and then the y-axis contains the number of times that name appears in the column.
I have used the following to count the number of time each name appears.
df.groupby('name').name.count()
Then tried to use the following to plot the graph. However, I get a key error messasge.
df.plot.bar(x='name', y=df.groupby('name').name.count())
Anyone able to tell me what I am doing wrong?
Thanks
I believe you need plot Series returned from count function by Series.plot.bar:
df.groupby('name').name.count().plot.bar()
Or use value_counts:
df['name'].value_counts().plot.bar()