I have Excel file(.xls) with Value and Currency (Example: USD, MYR... using format cell currency)
when i use xlrd to read, it only contain value only.
i search through online, openpyxl have this function, but not supported .xls file.
i need to know which currency is using.
may i know any other method?
Try reading using pandas
import pandas as pd
df = pd.read_excel('Your xls filename')
And now you can access your columns like this
print(df[col1])
For more info, refer - https://pythonspot.com/read-xls-with-pandas/
Related
Please take a look at the below text:
Mr. Manimaran R MMTFD NL20824448862,Room no-206
I have around half a million cells like this and i want to extract the ID number from this text using a formula. The problem that i am facing is that some ids start with NL some with NH and some with IN/IWA and the length of the text string containing the ids is also different (13/14/15 etc).
Is there any formula through which i can extract these ids??
Currently I am using this formula =MID(text,FIND("NH",text,1),15).
But i need to change it everytime for NL/IN as also for 14/15 etc.
Use of external tools is the way to go with that much variance in what you need to extract.
How about the following (assuming text is in cell C3 (basically pivoting off the comma and looking back)
=right(mid(C3, find(",",C3)-16,16),len(mid(C3, find(",",C3)-16,16))-find(" ",mid(C3, find(",",C3)-16,16)))
You can use pandas with python3 to easily and quickly do such task.
In python3 shell
import pandas as pd
df= pd.read_excel('./your_excel_file.xlsx') ##import from excel
df['ID']=df['Data_header_name'].str.split(' ',expand=True)[4].str.split(',',expand=True)[0] ##here you can use any relevant filters to get what you want
df.to_excel('output_excel.xlsx') ## save to excel
You also need to install openpyxl, xlrd, numpy, pandas using pip
pip install openpyxl xlrd numpy pandas
I have a dataset saved in an xls file.
In this dataset there are 4 columns that represent dates, in the format dd/mm/yyyy.
My problem is that when I read it in python using pandas and the function read_excel all the columns are read as string, except one, read as datetime64[ns], also if I specify dtypes={column=str}. Why?
Dates in Excel are frequently stored as numbers, which allows you to do things like subtract them, even though they might be displayed as human-readable dates like dd/mm/yyyy. Pandas is handily taking those numbers and interpreting them as dates, which lets you deal with them more flexibly.
To turn them into strings, you can use the converters argument of pd.read_excel like so:
df = pd.read_excel(filename, converters={'name_of_date_column': lambda dt: dt.strftime('%d/%m/%Y')})
The strftime method lets you format dates however you like. Specifying a converter for your column lets you apply the function to the data as you read it in.
I am doing some simple analysis using quantmod, my file is in Excel csv file.
The first column is the date format YYYY-MM-DD, I then have ten columns containing price data, each represents a fund or index. None of the data is on yahoo, so I cannot use getSymbols.
Could someone give the code to bring the excel file into R in a format workable with Quantmod in an understandable form that a non-programmer can understand?
I think the issue you have is that if you read the CSV file into R it is a dataframe object. Use the class() function to confirm.
library(tidyverse)
library(quantmod)
library(timekt)
my_data <- readr::read_csv('my excel file.csv')
class(my_data)
To use quantmod function your data needs to be in an xts object (time-series object), it can't be in a dataframe. You can convert a dataframe that has a date/index column into an xts object using the timekt::tk_xts() function. And then you should be able to use quantmod functions for analysis on your data.
my_xts <- timekt::tk_xts(my_data)
quantmod::monthlyReturns(my_xts)
import pandas as pd
batch=pd.read_excel('batch.xlsx')
stock_report=pd.read_excel('Stock_Report.xlsx')
Result_stock=pd.merge(stock_report,batch[['Batch','Cost price']], on='Batch').fillna(0)
Result_stock2=pd.merge(Result_stock,batch[['Item number',' Batch MRP']], on='Item number').fillna(0)
Result_stock2['Total']=Result_stock2['Posted quantity']*Result_stock2['Cost price']
I need to change the value of Column(Total) for Result_stock2 by multiplying it with two column value if it has 0.
You need to learn some formatting. Please format your code so we can read.
If I understood what you mean and your script is working fine so far, you should just simply add:
Result_stock2.loc[Result_stock2['Total']==0,'Total']=(****OPERATION YOU NEED****)
example in 'OPERATION'
Result_stock2.loc[Result_stock2['Total']==0,'Posted quantity']*(Result_stock2.loc[Result_stock2['Total']==0,'Cost price']-5)
It's not a beautiful code but will do what you need.
I am trying to extract the date from a date timestamp in excel. I currently have a data file with a mixture of date formats including date only and date timestamps. This is causing me problems as I am importing the data into SAS and it cannot read both the date only and date timestamps under the same column.
I have tried in Excel converting the timestamp to a date using the following formula:
=DATEVALUE(DAY(E32) & "/" & MONTH(E32) & "/" & YEAR(E32))
This works in excel and converts the date so that they are all formatted the same and therefore gets around the issue of the timestamp. However when I import the data into SAS, I get null values if the day is greater than 12, i.e. it is reading the date as mm/dd/yyyy. For example:
Excel Date SAS Import Date
09/12/2016 09/12/2016
15/12/2016 #VALUE!
I tried to reformat this in excel using the following to see if it would get around the issue:
=DATEVALUE(MONTH(E32) & "/" & DAY(E32) & "/" & YEAR(E32))
But I then get the same SAS error in excel.
Can anyone help suggest a formula to use in excel that will get around this issue or advice on importing the data into SAS?
It sounds like your Excel data is in DMY format, but SAS is using MDY. You can check SAS by running the following code :
proc options option=datestyle;
run;
If it is MDY, then change it (and if you're in the UK ask your SAS admin to change the default setting)
option datestyle='DMY';
You can also check the locale value, which in the UK will be EN_GB. This value determines the datestyle value used when working with dates.
proc options option=locale;
run;
If you asked SAS to import from an XLSX file then it should be able to tell that the column contains dates, independent of which display format you have attached to the cells. Make sure that all of the cells in a single column are the same type of data and use the same display format.
CSV files are not Excel files and so there is no place to put a formula or any metadata about what type of data is in each column. If you use PROC IMPORT to read the CSV file then SAS will have to guess at what type of data each column in the CSV contains. If you are saving an Excel files as a CSV file for later reading into SAS or other software then you should format your date columns using yyyy/mm/dd format in Excel to prevent confusion that can be caused by different defaults for month and day order. Nobody uses YDM order.
Since a CSV file is just a text file if you want complete control over how SAS reads the date strings then just write the data step to read it yourself. You could run PROC IMPORT and then recall the code that it generates and modify it to read your data. You could read the string into a character variable and then write your own statements to convert it using say the INPUT() function.
If the column has some date values and some date time values then you could try using the ANYDTDTE informat to pull just the date part. That informat should properly handle 15/10/2016 even if your LOCALE settings are for US or other locations where dates are normally represented in MDY order and not DMY order.
If your dates are consistently in the DMY order then use DDMMYY informat to prevent the LOCALE setting from causing PROC IMPORT or ANYDTDTE informat to convert 12/10/2016 to December 10th instead of October 12th. But if your text file actually has some rows with dates in month first order and others in day first order then you will really need some extra information to properly tell the difference between December 10th and October 12th.