how to check all values in particular column has same data type or not?Counting indexes in pandasPandas Query Optimization On Multiple ColumnsOutlier detection by unsupervised algorithm: Fraud DetectionMerge information of rows with same dateTraining on data with inherently non-applicable data cellsHow to print x-axes labels in pandas.Series.plot()?Processing csv file with more than 700K rows of dataUnderstanding missing values in datasetChange values of a particular column to value_count()Data sets that have strings and numerical data all in one column

Is American Sign Language phonetic?

Conveying the idea of "down the road" (i.e. in the future)

Does every Ubuntu question answer apply to it's derivatives? (Xubuntu, Lubuntu, Kubuntu)

Why is my vegetable stock bitter, but the chicken stock not?

Redirect output on-the-fly - looks not possible in Linux, why?

Can an animal produce milk all the time?

What benefits are there to blocking most search engines?

Can I voluntarily exit from the US after a 20 year overstay, or could I be detained at the airport?

How is the speed of nucleons in the nucleus measured?

How to print variable value in next line using echo command

Today I am 20 but next year I will turn 22

Has Boris Johnson ever referred to any of his opponents as "traitors"?

SHA3-255, one bit less

As an interviewer, how to conduct interviews with candidates you already know will be rejected?

Should I hang doors before or after drywall?

Can we calculate the orbit of exoplanets?

What is the origin of the minced oath “Jiminy”?

Does python reuse repeated calculation results?

What's the correct way to determine turn order in this situation?

Does the DOJ's declining to investigate the Trump-Zelensky call ruin the basis for impeachment?

Could the Queen overturn the UK Supreme Court ruling regarding prorogation of Parliament?

How fast are we moving relative to the CMB?

Can I pay off my mortgage with a new one?

In 1700s, why was 'books that never read' grammatical?



how to check all values in particular column has same data type or not?


Counting indexes in pandasPandas Query Optimization On Multiple ColumnsOutlier detection by unsupervised algorithm: Fraud DetectionMerge information of rows with same dateTraining on data with inherently non-applicable data cellsHow to print x-axes labels in pandas.Series.plot()?Processing csv file with more than 700K rows of dataUnderstanding missing values in datasetChange values of a particular column to value_count()Data sets that have strings and numerical data all in one column






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









1












$begingroup$


I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:



1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu


In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.



Note: I am using Pandas.










share|improve this question







New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$













  • $begingroup$
    In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
    $endgroup$
    – Kiritee Gak
    7 hours ago










  • $begingroup$
    @KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).
    $endgroup$
    – jottbe
    7 hours ago










  • $begingroup$
    I stand corrected. Thanks :)
    $endgroup$
    – Kiritee Gak
    6 hours ago

















1












$begingroup$


I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:



1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu


In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.



Note: I am using Pandas.










share|improve this question







New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$













  • $begingroup$
    In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
    $endgroup$
    – Kiritee Gak
    7 hours ago










  • $begingroup$
    @KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).
    $endgroup$
    – jottbe
    7 hours ago










  • $begingroup$
    I stand corrected. Thanks :)
    $endgroup$
    – Kiritee Gak
    6 hours ago













1












1








1





$begingroup$


I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:



1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu


In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.



Note: I am using Pandas.










share|improve this question







New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$




I have column 'ABC' which has 5000 rows. Currently, dtype of column is object. Mostly it has string values but some values dtype is not string, I want to find all those rows and modify those rows. Column is as following:



1 abc
2 def
3 ghi
4 23
5 mno
6 null
7 qwe
8 12-11-2019
...
...
...
4900 ert
5000 tyu


In above case, I can use for loop to find out rows which do not have desired dtype. I just wanted to know, is their better way to solve this issue.



Note: I am using Pandas.







python pandas data-cleaning numpy






share|improve this question







New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question







New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question






New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 8 hours ago









KiranKiran

1084 bronze badges




1084 bronze badges




New contributor



Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




Kiran is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • $begingroup$
    In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
    $endgroup$
    – Kiritee Gak
    7 hours ago










  • $begingroup$
    @KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).
    $endgroup$
    – jottbe
    7 hours ago










  • $begingroup$
    I stand corrected. Thanks :)
    $endgroup$
    – Kiritee Gak
    6 hours ago
















  • $begingroup$
    In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
    $endgroup$
    – Kiritee Gak
    7 hours ago










  • $begingroup$
    @KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).
    $endgroup$
    – jottbe
    7 hours ago










  • $begingroup$
    I stand corrected. Thanks :)
    $endgroup$
    – Kiritee Gak
    6 hours ago















$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
$endgroup$
– Kiritee Gak
7 hours ago




$begingroup$
In pandas dtypes can be inferred by trying to cast them and making un-castable ones to string dtypes as in object, which means all elements in a single column will be in a same datatype. You cant have two diff. row elements in the same column to be of different datatypes.
$endgroup$
– Kiritee Gak
7 hours ago












$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).
$endgroup$
– jottbe
7 hours ago




$begingroup$
@KiriteeGak: I think that is not quite true. You can test that yourself. Create a dataframe, with at least two rows indexed 1 and 2. Then do df.loc[1, 'new_column']= 'my_value'. Then do df['new_column'].map(type). You will see, that all but the first row contain floats. That is because the other rows contain NaN, which is a float and not a str. Likewise you could mix in other object types in your object column if you like (but it is probably not a very good idea).
$endgroup$
– jottbe
7 hours ago












$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago




$begingroup$
I stand corrected. Thanks :)
$endgroup$
– Kiritee Gak
6 hours ago










1 Answer
1






active

oldest

votes


















2














$begingroup$

You can get the type of the entries of your column with map:



df['ABC'].map(type)


So to filter on all values, which are not stored as str, you can use:



df['ABC'].map(type) != str


If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:



df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')


But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.






share|improve this answer











$endgroup$














  • $begingroup$
    thanks, it helped..
    $endgroup$
    – Kiran
    7 hours ago












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);







Kiran is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f60955%2fhow-to-check-all-values-in-particular-column-has-same-data-type-or-not%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














$begingroup$

You can get the type of the entries of your column with map:



df['ABC'].map(type)


So to filter on all values, which are not stored as str, you can use:



df['ABC'].map(type) != str


If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:



df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')


But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.






share|improve this answer











$endgroup$














  • $begingroup$
    thanks, it helped..
    $endgroup$
    – Kiran
    7 hours ago















2














$begingroup$

You can get the type of the entries of your column with map:



df['ABC'].map(type)


So to filter on all values, which are not stored as str, you can use:



df['ABC'].map(type) != str


If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:



df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')


But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.






share|improve this answer











$endgroup$














  • $begingroup$
    thanks, it helped..
    $endgroup$
    – Kiran
    7 hours ago













2














2










2







$begingroup$

You can get the type of the entries of your column with map:



df['ABC'].map(type)


So to filter on all values, which are not stored as str, you can use:



df['ABC'].map(type) != str


If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:



df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')


But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.






share|improve this answer











$endgroup$



You can get the type of the entries of your column with map:



df['ABC'].map(type)


So to filter on all values, which are not stored as str, you can use:



df['ABC'].map(type) != str


If however you just want to check if some of the rows contain a string, that has a special format (like a date), you can check this with a regex like:



df['ABC'].str.match('[0-9]4-[0-9]2-[0-9]2')


But of course, that is no exact date check. E.g. it would also return True for values like 0000-13-91, but this was only meant to give you an idea anyways.







share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered 7 hours ago









jottbejottbe

18210 bronze badges




18210 bronze badges














  • $begingroup$
    thanks, it helped..
    $endgroup$
    – Kiran
    7 hours ago
















  • $begingroup$
    thanks, it helped..
    $endgroup$
    – Kiran
    7 hours ago















$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago




$begingroup$
thanks, it helped..
$endgroup$
– Kiran
7 hours ago











Kiran is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded

















Kiran is a new contributor. Be nice, and check out our Code of Conduct.












Kiran is a new contributor. Be nice, and check out our Code of Conduct.











Kiran is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Data Science Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f60955%2fhow-to-check-all-values-in-particular-column-has-same-data-type-or-not%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480