0

I'm creating a dataframe by using pd.read_excel() function. using this way to read a file

df = pd.read_excel(file_url, dtype = str, nrows=100, header=None, encoding="unicode_escape")

but in case of excel file have date formatted cells then after reading the file the values is look like 2021-08-07 14:17:20 but i want only 2021-08-07.

If any one know please help me. Thanks !!

Anshu
  • 1,277
  • 2
  • 13
  • 28
  • 1
    @ThePyGuy hi actually i don't now which column have datetime value because of i'm reading a fie. if i'm trying to get the df.dtypes then all the types are objects and str , that why i'm not able to use the above shared answer. – Anshu Aug 07 '21 at 09:03
  • Then you asked a wrong question, your question should have been how to identify datetime columns while reading excel/csv files. You can take a look at [datetime dtypes in pandas read_csv](https://stackoverflow.com/questions/21269399/datetime-dtypes-in-pandas-read-csv), it is almost the same for both the csv and excel files, you can refer to the doc for [pandas.read_excel](https://pandas.pydata.org/docs/reference/api/pandas.read_excel.html) – ThePyGuy Aug 07 '21 at 09:06
  • 1
    And if you still struggle with it, then edit and update the question and also mention in the question why the duplicate marked question's solution doesn't work for you, if you want this question to be reopened. – ThePyGuy Aug 07 '21 at 09:09
  • @ThePyGuy can you kinldy help me . i just need to format the datetime to date only , but i don't know which column have datetime value in dataframe. and also edit my question. – Anshu Aug 07 '21 at 09:12
  • Okay, Try [this solution](https://stackoverflow.com/questions/21269399/datetime-dtypes-in-pandas-read-csv/37453925#37453925) with `read_excel`, and look at the datatypes after reading the file doing `df.dtypes`, see if the column having `datetime` values are converted to `datetime` or not. – ThePyGuy Aug 07 '21 at 09:15
  • no column type is object or str but value is datetime. – Anshu Aug 07 '21 at 09:16
  • Did you try the solution in the link that I mentioned above? – ThePyGuy Aug 07 '21 at 09:17
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235726/discussion-between-anshu-and-thepyguy). – Anshu Aug 07 '21 at 09:19

0 Answers0